Src/Pscx.Core/Reflection/FastInvoke.cs
/// <summary>Gets the instance creator delegate that can be use to create instances of the specified type.</summary>
/// <param name="type">The type of the objects we want to create.</param>
/// <returns>A delegate that can be used to create the objects.</returns>
Gets the instance creator delegate that can be use to create instances of the specified type.
Gets the instance creator delegate that can be use to create instances of the specified type .
public static FastCreateInstanceHandler GetInstanceCreator(Type type)
        {
            DynamicMethod dynamicMethod = new DynamicMethod(string.Empty, type, new Type[0], typeof(DynamicCalls).Module);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();
            ilGenerator.Emit(OpCodes.Newobj, type.GetConstructor(Type.EmptyTypes));
            ilGenerator.Emit(OpCodes.Ret);
            FastCreateInstanceHandler creator = (FastCreateInstanceHandler)dynamicMethod.CreateDelegate(typeof(FastCreateInstanceHandler));
            return creator;
        }
public static FastCreateInstanceHandler GetInstanceCreator ( Type type ) { DynamicMethod dynamicMethod = new DynamicMethod ( string . Empty , type , new Type [ 0 ] , typeof ( DynamicCalls ) . Module ) ; ILGenerator ilGenerator = dynamicMethod . GetILGenerator ( ) ; ilGenerator . Emit ( OpCodes . Newobj , type . GetConstructor ( Type . EmptyTypes ) ) ; ilGenerator . Emit ( OpCodes . Ret ) ; FastCreateInstanceHandler creator = ( FastCreateInstanceHandler ) dynamicMethod . CreateDelegate ( typeof ( FastCreateInstanceHandler ) ) ; return creator ; }
Gets the instance creator delegate that can be use to create instances of the specified type.
Gets the instance creator delegate that can be use to create instances of the specified type .
// generates a dynamic method to generate a FastCreateInstanceHandler delegate // generates code to create a new object of the specified type using the default constructor // returns the value to the caller // converts the DynamicMethod to a FastCreateInstanceHandler delegate to create the object
A delegate that can be used to create the objects.
A delegate that can be used to create the objects .
type
Type
The type of the objects we want to create.
The type of the objects we want to create .