Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is but it's not a simple solution. Essentially you create a dynamic method and then create a delegate from that and use it.</p> <pre><code>public static BaseBuilder Create(Type builderType, HttpContextBase httpContext, PathDataDictionary pathData) { if (!builderType.IsSubclassOf(baseBuilderType)) return null; BuilderConstructorDelegate del; if (builderConstructors.TryGetValue(builderType.FullName, out del)) return del(httpContext, pathData); DynamicMethod dynamicMethod = new DynamicMethod("CreateBaseBuilderInstance", builderType, constructorMethodArgs, builderType); ILGenerator ilGenerator = dynamicMethod.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Newobj, builderType.GetConstructor(constructorMethodArgs)); ilGenerator.Emit(OpCodes.Ret); del = (BuilderConstructorDelegate)dynamicMethod.CreateDelegate(typeof(BuilderConstructorDelegate)); builderConstructors.TryAdd(builderType.FullName, del); return del(httpContext, pathData); } </code></pre> <p>Here is some code I use in the <a href="http://www.matlus.com/2010/11/builder-for-aspnet/" rel="nofollow">Builder for ASP.NET</a></p> <p>framework in the BuilderFactory.</p> <p>If it's not clear in the code, you should know that once you have a delegate then that delete is stored in the dictionary called builderConstructors in the code above. So the next time the factory simply uses the delegate.</p> <p>In this particular case the class requires two parameters in its constructor. If you're using the default constructor for your classes things are a little simpler.</p> <p><a href="http://www.matlus.com/2010/11/high-performance-class-factory/" rel="nofollow">High Performance Class Factory</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload