Skip to content

GetDeclaration fails on nested generic types #29

@ZacharyPatten

Description

@ZacharyPatten

Description

Just FYI your "Type.GetDeclaration()" extension fails for nested generic types. Example:

class A
{
    class B<D>
    {
        class C<E> {  }
    }
}

typeof(A.B<int>.C<string>).GetDeclaration();

It currently throws an InvalidOperationException.

I'm not sure what you would want to do in these cases since it is a nested type and the declaration requires the parent type as well. In my opinion it should probably return the declaration for only that nested class (and not the parents)... But that is up to you of course.

At a minimum you should probably throw a custom ArgumentException with a custom message.

If you remove types:

typeof(A.B<>.C<>).GetDeclaration()

It returns

"C<D, E>"

And that is definitely incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions