Skip to content

Expose the ability to create signature generic instance types. #27152

@ghost

Description

@ghost

Proposed Api:

public class Type
{
      public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments);
}

Rationale

Last year, we added an api and the concept of Signature Types (https://github.com/dotnet/corefx/issues/16567). What we punted on at a time is the api support to let third party reimplementations of Reflection fully support the use of Signature Types in querying type members. In particular, when searching for a method that takes a generic instance that has a signature type as a type argument, the app needs to write something like this:

          //
          // Searching for Foo<M>(IList<M>)
          //
          Type signatureType = Type.MakeGenericMethodParameter(0);
          Type[] typeParameters = { typeof(IList<>).MakeGenericType(signatureType) };
          MethodInfo m = t.GetMethod("Foo", 1, typeParameters);

And this works because as part of that feature, RuntimeType.MakeGenericType() was changed to recognize the SignatureType created by MakeGenericMethodParameter() and create the appropriate signature type object.

It does so, however, using an internal constructor. Implementers outside of CoreLib cannot access this.

And we're in the process of writing such an implementation now: (https://github.com/dotnet/corefx/issues/2800 (Assembly.ReflectionOnlyLoad replacement - TypeInfo and family implementation over System.Reflection.Metadata))

It will need this api to support the search pattern above.

The implementation of this is simplicity itself:

      public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments)
      {
             // maybe add some rudimentary parameter validation - keep it simple - the only intended customers
             // are third-party implementers of Type.MakeGenericType() - it would already have done the
             // validation.
            return new SignatureConstructedGenericType(genericTypeDefinition, typeArguments)
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions