Skip to content

Creating a ValueTuple with a TypeBuilder element #111760

Closed Answered by huoyaoyuan
jgh07 asked this question in Q&A
Discussion options

You must be logged in to vote

It's mentioned in documentation: https://learn.microsoft.com/en-us/dotnet/fundamentals/reflection/how-to-define-a-generic-type-with-reflection-emit

The GetConstructor method is not supported on a GenericTypeParameterBuilder, so it is not possible to get the constructor of List<TFirst> directly. First, it is necessary to get the constructor of the generic type definition List<T> and then to call a method that converts it to the corresponding constructor of List<TFirst>.

Although the scenario isn't exact the same with this issue (TypeBuilderInstantiation), the solution is the same:

var openCtor = typeof(ValueTuple<>).GetConstructor([typeof(ValueTuple<>).GetGenericArguments()[0]]);
var ctor =

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jgh07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants