Skip to content

Instantly share code, notes, and snippets.

@forcewake
Last active December 27, 2015 22:49
Show Gist options
  • Save forcewake/7401725 to your computer and use it in GitHub Desktop.
Save forcewake/7401725 to your computer and use it in GitHub Desktop.
CreateInstance for class with internal ctor
Type type = typeof (Bootstrap<>);
Type genericType = type.MakeGenericType(new Type[] {typeof (TModel)});
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
object instantiatedType = Activator.CreateInstance(genericType, flags, null, new HtmlHelper<TModel>[] { helper }, null);
return (Bootstrap<TModel>)instantiatedType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment