Created
September 17, 2016 01:31
-
-
Save nbxx/69e6d0d04d9be6fe7d884439361b74be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static object CreateInstanceGeneric(Type source, Type[] typeArguments, params object[] args) | |
{ | |
object result = null; | |
Type genericType = source.MakeGenericType(typeArguments); | |
try | |
{ | |
result = Activator.CreateInstance(genericType, args); | |
} | |
catch | |
{ | |
result = FormatterServices.GetUninitializedObject(genericType); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment