Skip to content

Instantly share code, notes, and snippets.

@nbxx
Created September 17, 2016 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbxx/3c360132e7c072356110bd5797602d79 to your computer and use it in GitHub Desktop.
Save nbxx/3c360132e7c072356110bd5797602d79 to your computer and use it in GitHub Desktop.
public static object CreateInstance(Type source, params object[] args)
{
if (source == typeof(string))
{
return string.Empty;
}
object result = null;
try
{
result = Activator.CreateInstance(source, args);
}
catch
{
result = FormatterServices.GetUninitializedObject(source);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment