Answers for "use generic method from type object c#"

C#
1

create new object from generic c#

return (T)Activator.CreateInstance(typeof(T), new object[] { param });
Posted by: Guest on March-23-2020
1

c# reflection create generic type

Type generic = typeof(Dictionary<,>);

// Create an array of types to substitute for the type parameters of Dictionary. The key is of type string, and the type to be contained in the Dictionary is Test.
Type[] typeArgs = { typeof(string), typeof(Test) };

// Create a Type object representing the constructed generic type.
Type constructed = generic.MakeGenericType(typeArgs);

var instance = Activator.CreateInstance(constructedType);
Posted by: Guest on June-01-2020

Code answers related to "use generic method from type object c#"

C# Answers by Framework

Browse Popular Code Answers by Language