I
I
iremezoff2011-10-20 20:06:20
C++ / C#
iremezoff, 2011-10-20 20:06:20

Reflection and generic C# types?

In general, the situation is as follows:
1. There is a generic type, for example class MyGeneric<T> {public T value;}
2. There is a type variable of type Type, the value of which stores information about a certain type. The information is obtained by the typeof(SomeType) operation.
Can I create an object of a generic type and pass as a parameter exactly the type that is stored in the type variable Type?
Example:
Typetype = typeof(DateTime);
I want a generic type object like MyGeneric<DateTime>. But how to pass as a parameter what is stored in type is a mystery

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rumatavz, 2011-10-20
@rumatavz

Type.MakeGenericType

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question