public ILReflector( Type reflectedType, FieldInfo[] fields, PropertyInfo[] properties) { this.m_reflectedType = reflectedType; this.m_refinedType = reflectedType.IsValueType ? reflectedType.MakeByRefType() : reflectedType; InitializeType(); m_getAllInvoker = CreateGetFieldValuesMethod(fields); m_setAllInvoker = CreateSetFieldValuesMethod(fields); this.m_createInstanceMethod = CreateCreateInstanceMethod(); for (int i = 0; i < fields.Length; i++) { m_getFieldValueInvokers.Add(fields[i], CreateGetFieldValueMethod(fields[i])); m_setFieldValueInvokers.Add(fields[i], CreateSetFieldValueMethod(fields[i])); } for (int i = 0; i < properties.Length; i++) { m_getPropertyValueInvokers.Add(properties[i], CreateGetPropertyValueMethod(properties[i])); m_setPropertyValueInvokers.Add(properties[i], CreateSetPropertyValueMethod(properties[i])); } }
internal InstanceProvider(CreateInstanceDelegate creator) { if (creator == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("creator"); } this.creator = creator; }
public DirectFunctions() { EnumerateInstanceLayerProperties = VkHelpers.GetInstanceDelegate <EnumerateInstanceLayerPropertiesDelegate>(null, "vkEnumerateInstanceLayerProperties"); EnumerateInstanceExtensionProperties = VkHelpers.GetInstanceDelegate <EnumerateInstanceExtensionPropertiesDelegate>(null, "vkEnumerateInstanceExtensionProperties"); CreateInstance = VkHelpers.GetInstanceDelegate <CreateInstanceDelegate>(null, "vkCreateInstance"); }
private static void CreateDynamicAssembly() { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert(); Type[] types = new Type[] { typeof(Type), typeof(Type), typeof(string) }; MethodInfo methodInfo = typeof(Delegate).GetMethod("CreateDelegate", types); DynamicMethod method = new DynamicMethod("CreateDelegate", typeof(Delegate), types); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "targetType"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); ILGenerator iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateDelegate1 = (CreateDelegate1Delegate)method.CreateDelegate(typeof(CreateDelegate1Delegate)); types = new Type[] { typeof(Type), typeof(object), typeof(string) }; methodInfo = typeof(Delegate).GetMethod("CreateDelegate", types); method = new DynamicMethod("CreateDelegate", typeof(Delegate), types); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "target"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateDelegate2 = (CreateDelegate2Delegate)method.CreateDelegate(typeof(CreateDelegate2Delegate)); types = new Type[] { typeof(Type), typeof(object[]) }; methodInfo = typeof(Activator).GetMethod("CreateInstance", types); method = new DynamicMethod("CreateInstance", typeof(object), types); method.DefineParameter(1, ParameterAttributes.In, "type"); method.DefineParameter(2, ParameterAttributes.In, "arguments"); iLGenerator = method.GetILGenerator(4); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateInstance = (CreateInstanceDelegate)method.CreateDelegate(typeof(CreateInstanceDelegate)); types = new Type[] { typeof(object), typeof(object[]) }; Type[] parameterTypes = new Type[] { typeof(MethodInfo), typeof(object), typeof(object[]) }; methodInfo = typeof(MethodInfo).GetMethod("Invoke", types); method = new DynamicMethod("InvokeMethod", typeof(object), parameterTypes); method.DefineParameter(1, ParameterAttributes.In, "method"); method.DefineParameter(2, ParameterAttributes.In, "instance"); method.DefineParameter(3, ParameterAttributes.In, "args"); iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Callvirt, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_InvokeMethod = (InvokeMethodDelegate)method.CreateDelegate(typeof(InvokeMethodDelegate)); }
public DirectFunctions() { EnumerateInstanceLayerProperties = VkHelpers.GetInstanceDelegate<EnumerateInstanceLayerPropertiesDelegate>(null, "vkEnumerateInstanceLayerProperties"); EnumerateInstanceExtensionProperties = VkHelpers.GetInstanceDelegate<EnumerateInstanceExtensionPropertiesDelegate>(null, "vkEnumerateInstanceExtensionProperties"); CreateInstance = VkHelpers.GetInstanceDelegate<CreateInstanceDelegate>(null, "vkCreateInstance"); }
public MultiTypeObjectPool(CreateInstanceDelegate createInstanceMethod = null, Arg1Delegate <IPoolable> disposeInstanceMethod = null, Arg1Delegate <IPoolable> getInstanceMethod = null, Arg1Delegate <IPoolable> returnInstanceMethod = null) { poolDict = new Dictionary <Type, ObjectPool <IPoolable> >(); this.CreateInstanceMethod = createInstanceMethod; this.DisposeInstanceMethod = disposeInstanceMethod; this.GetInstanceMethod = getInstanceMethod; this.ReturnInstanceMethod = returnInstanceMethod; }
internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime) { this.useSession = dispatch.ChannelDispatcher.Session; this.immutableRuntime = immutableRuntime; this.host = (dispatch.ChannelDispatcher == null) ? null : dispatch.ChannelDispatcher.Host; this.initializers = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers); this.provider = dispatch.InstanceProvider; this.singleton = dispatch.SingletonInstanceContext; this.transactionAutoCompleteOnSessionClose = dispatch.TransactionAutoCompleteOnSessionClose; this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete; this.isSynchronized = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple); this.instanceContextProvider = dispatch.InstanceContextProvider; if (this.provider == null) { ConstructorInfo constructor = null; if (dispatch.Type != null) { constructor = InstanceBehavior.GetConstructor(dispatch.Type); } if (this.singleton == null) { if (dispatch.Type != null && (dispatch.Type.IsAbstract || dispatch.Type.IsInterface)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceTypeNotCreatable))); } if (constructor == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoDefaultConstructor))); } } if (constructor != null) { if (this.singleton == null || !this.singleton.IsWellKnown) { InvokerUtil util = new InvokerUtil(); CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor); this.provider = new InstanceProvider(creator); } } } if (this.singleton != null) { this.singleton.Behavior = this; } }
/// <summary> /// Constructs a ConcurrentPool object. /// </summary> /// <param name="name">The name for the ConcurrentPool instance.</param> /// <param name="constructor">The <see cref="CreateInstanceDelegate"/> delegate that is used to construct the <see cref="IRecyclable"/> instance.</param> /// <param name="initialCapacity">Initial pool capacity.</param> public ConcurrentPool(string name, CreateInstanceDelegate constructor, int initialCapacity) { this.Name = name; this.Constructor = constructor; this.Releaser = new ReleaseInstanceDelegate((this as IRecycler).Release); if (initialCapacity > 0) { // Create instances for (int i = 0; i < initialCapacity; ++i) { Instances.Enqueue(CreateInstance()); } } }
/// <summary> /// Allocates a new instance of T. /// </summary> /// <returns>Allocated instance of T.</returns> protected virtual T CreateInstance() { // If there is no constructor defined, create a new one. if (this.Constructor == null) { this.Constructor = _ => Activator.CreateInstance <T>(); } // Create a new instance T instance = Constructor(this); instance.Bind(this.Releaser); return(instance); }
public CreateInstanceDelegate ConstructeInstance(Type type) { CreateInstanceDelegate instanceDelegate = null; if (!m_instanceDelegateDic.TryGetValue(type, out instanceDelegate)) { DynamicMethod dynamicMethod = new DynamicMethod("CreateInstance", type, new Type[0]); ConstructorInfo ctorInfo = type.GetConstructor(new Type[0]); ILGenerator ilGen = dynamicMethod.GetILGenerator(); ilGen.Emit(OpCodes.Newobj, ctorInfo); ilGen.Emit(OpCodes.Ret); instanceDelegate = (CreateInstanceDelegate)dynamicMethod.CreateDelegate(typeof(CreateInstanceDelegate)); m_instanceDelegateDic.Add(type, instanceDelegate); } return(instanceDelegate); }
internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime) { this.immutableRuntime = immutableRuntime; initializers = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers); provider = dispatch.InstanceProvider; singleton = dispatch.SingletonInstanceContext; isSynchronized = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple); instanceContextProvider = dispatch.InstanceContextProvider; if (provider == null) { ConstructorInfo constructor = null; if (dispatch.Type != null) { constructor = InstanceBehavior.GetConstructor(dispatch.Type); } if (singleton == null) { if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable)); } if (constructor == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor)); } } if (constructor != null) { if (singleton == null || !singleton.IsWellKnown) { InvokerUtil util = new InvokerUtil(); CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor); provider = new InstanceProvider(creator); } } } if (singleton != null) { singleton.Behavior = this; } }
public override void Configure (object appHostConfig, object webAppConfig, IApplicationServer server, IListenerTransport listenerTransport, Type appHostTransportType, object transportConfig) { RawHostConfig config = appHostConfig as RawHostConfig; if (config != null) { Logger.Level = config.Log.Level; Logger.WriteToConsole = config.Log.WriteToConsole; requestType = Type.GetType(config.RequestType); if (requestType == null) { Logger.Write(LogLevel.Error, "Couldn't find type '{0}'", config.RequestType); throw new ArgumentException ("appHostConfig.Type"); } CreateRequestInstance = CreateDynamicMethod (requestType); } base.Configure (appHostConfig, webAppConfig, server, listenerTransport, appHostTransportType, transportConfig); }
internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime) { _immutableRuntime = immutableRuntime; _initializers = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers); _provider = dispatch.InstanceProvider; _singleton = dispatch.SingletonInstanceContext; InstanceContextProvider = dispatch.InstanceContextProvider; if (_provider == null) { bool hasDefaultConstructor = dispatch.Type != null && InvokerUtil.HasDefaultConstructor(dispatch.Type); if (_singleton == null) { if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable)); } if (!hasDefaultConstructor) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor)); } } if (!hasDefaultConstructor) { if (_singleton == null || !_singleton.IsWellKnown) { CreateInstanceDelegate creator = InvokerUtil.GenerateCreateInstanceDelegate(dispatch.Type); _provider = new InstanceProvider(creator); } } } if (_singleton != null) { _singleton.Behavior = this; } }
/// <summary> /// Constructs an entity type. /// </summary> public EntityType(string entityTypeName, EntityCategory category, int version, CreateInstanceDelegate createInstanceDelegate, IEnumerable <EntityPropertyDefinition> propertyDefinitions) { if (entityTypeName == null) { throw new ArgumentNullException("entityTypeName"); } if (createInstanceDelegate == null) { throw new ArgumentNullException("createInstanceDelegate"); } if (propertyDefinitions == null) { throw new ArgumentNullException("propertyDefinitions"); } // this.name = entityTypeName; this.category = category; this.repositoryVersion = version; this.createInstanceDelegate = createInstanceDelegate; this.propertyDefinitions = new List <EntityPropertyDefinition>(); // Sort property definitions: // EntityFieldDefinitions first, EntityInnerObjectsDefinition afterwards foreach (EntityPropertyDefinition propertyDef in propertyDefinitions) { if (propertyDef is EntityFieldDefinition) { this.propertyDefinitions.Add(propertyDef); } } foreach (EntityPropertyDefinition propertyDef in propertyDefinitions) { if (propertyDef is EntityInnerObjectsDefinition) { this.propertyDefinitions.Add(propertyDef); } } }
public override void Configure(object appHostConfig, object webAppConfig, IApplicationServer server, IListenerTransport listenerTransport, Type appHostTransportType, object transportConfig) { RawHostConfig config = appHostConfig as RawHostConfig; if (config != null) { Logger.Level = config.Log.Level; Logger.WriteToConsole = config.Log.WriteToConsole; requestType = Type.GetType(config.RequestType); if (requestType == null) { Logger.Write(LogLevel.Error, "Couldn't find type '{0}'", config.RequestType); throw new ArgumentException("appHostConfig.Type"); } CreateRequestInstance = CreateDynamicMethod(requestType); } base.Configure(appHostConfig, webAppConfig, server, listenerTransport, appHostTransportType, transportConfig); }
private static extern IntPtr OgreManagedArchiveFactory_Create(String archType, CreateInstanceDelegate createInstanceCallback, DestroyInstanceDelegate destroyInstanceCallback #if FULL_AOT_COMPILE , IntPtr instanceHandle #endif );
public PerformanceCounterMultipleInstanceWithAutoUpdateTotal(string categoryName, CreateInstanceDelegate instanceCreator) : base(categoryName, instanceCreator) { this.totalInstance = instanceCreator("_Total", null); }
private static void CreateDynamicAssembly() { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert(); Type[] types = new Type[] { typeof(Type), typeof(Type), typeof(string) }; MethodInfo methodInfo = typeof(Delegate).GetMethod("CreateDelegate", types); DynamicMethod method = new DynamicMethod("CreateDelegate", typeof(Delegate), types); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "targetType"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); ILGenerator iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateDelegate1 = (CreateDelegate1Delegate) method.CreateDelegate(typeof(CreateDelegate1Delegate)); types = new Type[] { typeof(Type), typeof(object), typeof(string) }; methodInfo = typeof(Delegate).GetMethod("CreateDelegate", types); method = new DynamicMethod("CreateDelegate", typeof(Delegate), types); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "target"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateDelegate2 = (CreateDelegate2Delegate) method.CreateDelegate(typeof(CreateDelegate2Delegate)); types = new Type[] { typeof(Type), typeof(object[]) }; methodInfo = typeof(Activator).GetMethod("CreateInstance", types); method = new DynamicMethod("CreateInstance", typeof(object), types); method.DefineParameter(1, ParameterAttributes.In, "type"); method.DefineParameter(2, ParameterAttributes.In, "arguments"); iLGenerator = method.GetILGenerator(4); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.EmitCall(OpCodes.Call, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_CreateInstance = (CreateInstanceDelegate) method.CreateDelegate(typeof(CreateInstanceDelegate)); types = new Type[] { typeof(object), typeof(object[]) }; Type[] parameterTypes = new Type[] { typeof(MethodInfo), typeof(object), typeof(object[]) }; methodInfo = typeof(MethodInfo).GetMethod("Invoke", types); method = new DynamicMethod("InvokeMethod", typeof(object), parameterTypes); method.DefineParameter(1, ParameterAttributes.In, "method"); method.DefineParameter(2, ParameterAttributes.In, "instance"); method.DefineParameter(3, ParameterAttributes.In, "args"); iLGenerator = method.GetILGenerator(5); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldarg_2); iLGenerator.EmitCall(OpCodes.Callvirt, methodInfo, null); iLGenerator.Emit(OpCodes.Ret); s_InvokeMethod = (InvokeMethodDelegate) method.CreateDelegate(typeof(InvokeMethodDelegate)); }
public PerformanceCounterMultipleInstance(string categoryName, CreateInstanceDelegate instanceCreator) { this.instanceCreator = instanceCreator; this.category = PerformanceCounterFactory.CreatePerformanceCounterCategory(categoryName); }
/// <summary> /// Constructs a ConcurrentPool object. /// </summary> /// <param name="name">The name for the ConcurrentPool instance.</param> /// <param name="constructor">The <see cref="CreateInstanceDelegate"/> delegate that is used to construct the <see cref="IRecyclable"/> instance.</param> public ConcurrentPool(string name, CreateInstanceDelegate constructor) : this(name, constructor, 0) { }
/// <summary> /// Creates a new instance of a packet pool. /// </summary> /// <param name="name">The name of the pool.</param> /// <param name="constructor">Provides a mechanism to create the packet instance.</param> public PacketPool(string name, CreateInstanceDelegate constructor) : base(name, constructor, 0) { }
internal InstanceProvider(CreateInstanceDelegate creator) { _creator = creator ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(creator)); }
private static void CreateDynamicAssembly() { // 1. Assert permissions demanded by the DynamicMethod ctor. new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert(); // BlessedAssert // 2. Create the transparent methods, each wrapping a call to a reflection method, // and cache a delegate to each method. Type[] parameterTypes; // signature of the reflection method Type[] wrappedParameterTypes; // signature of the wrapping method (when different) MethodInfo mi; // descriptor for the reflection method DynamicMethod method; // wrapping method ILGenerator il; // wrapping method's generator // 2a. Delegate.CreateDelegate( Type, Type, String ) parameterTypes = new Type[] { typeof(Type), typeof(Type), typeof(String) }; mi = typeof(Delegate).GetMethod("CreateDelegate", parameterTypes); method = new DynamicMethod("CreateDelegate", typeof(Delegate), parameterTypes); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "targetType"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); il = method.GetILGenerator(5); il.Emit(OpCodes.Ldarg_0); // push delegateType il.Emit(OpCodes.Ldarg_1); // push targetType il.Emit(OpCodes.Ldarg_2); // push methodName il.EmitCall(OpCodes.Call, mi, null); // call Delegate.CreateDelegate il.Emit(OpCodes.Ret); // return the result s_CreateDelegate1 = (CreateDelegate1Delegate)method.CreateDelegate(typeof(CreateDelegate1Delegate)); // 2b. Delegate.CreateDelegate( Type, Object, String ) parameterTypes = new Type[] { typeof(Type), typeof(Object), typeof(String) }; mi = typeof(Delegate).GetMethod("CreateDelegate", parameterTypes); method = new DynamicMethod("CreateDelegate", typeof(Delegate), parameterTypes); method.DefineParameter(1, ParameterAttributes.In, "delegateType"); method.DefineParameter(2, ParameterAttributes.In, "target"); method.DefineParameter(3, ParameterAttributes.In, "methodName"); il = method.GetILGenerator(5); il.Emit(OpCodes.Ldarg_0); // push delegateType il.Emit(OpCodes.Ldarg_1); // push target il.Emit(OpCodes.Ldarg_2); // push methodName il.EmitCall(OpCodes.Call, mi, null); // call Delegate.CreateDelegate il.Emit(OpCodes.Ret); // return the result s_CreateDelegate2 = (CreateDelegate2Delegate)method.CreateDelegate(typeof(CreateDelegate2Delegate)); // 2c. Activator.CreateInstance( Type, Object[] ) parameterTypes = new Type[] { typeof(Type), typeof(Object[]) }; mi = typeof(Activator).GetMethod("CreateInstance", parameterTypes); method = new DynamicMethod("CreateInstance", typeof(Object), parameterTypes); method.DefineParameter(1, ParameterAttributes.In, "type"); method.DefineParameter(2, ParameterAttributes.In, "arguments"); il = method.GetILGenerator(4); il.Emit(OpCodes.Ldarg_0); // push type il.Emit(OpCodes.Ldarg_1); // push arguments il.EmitCall(OpCodes.Call, mi, null); // call Activator.CreateInstance il.Emit(OpCodes.Ret); // return the result s_CreateInstance = (CreateInstanceDelegate)method.CreateDelegate(typeof(CreateInstanceDelegate)); // 2d. MethodInfo.Invoke(object, args) parameterTypes = new Type[] { typeof(Object), typeof(Object[]) }; wrappedParameterTypes = new Type[] { typeof(MethodInfo), typeof(Object), typeof(Object[]) }; mi = typeof(MethodInfo).GetMethod("Invoke", parameterTypes); method = new DynamicMethod("InvokeMethod", typeof(Object), wrappedParameterTypes); method.DefineParameter(1, ParameterAttributes.In, "method"); method.DefineParameter(2, ParameterAttributes.In, "instance"); method.DefineParameter(3, ParameterAttributes.In, "args"); il = method.GetILGenerator(5); il.Emit(OpCodes.Ldarg_0); // push method il.Emit(OpCodes.Ldarg_1); // push instance il.Emit(OpCodes.Ldarg_2); // push args il.EmitCall(OpCodes.Callvirt, mi, null); // call method.Invoke il.Emit(OpCodes.Ret); // return the result s_InvokeMethod = (InvokeMethodDelegate)method.CreateDelegate(typeof(InvokeMethodDelegate)); }
/// <summary> /// Constructs an entity type. /// </summary> public EntityType(string entityTypeName, EntityCategory category, int version, CreateInstanceDelegate createInstanceDelegate, IEnumerable<EntityPropertyDefinition> propertyDefinitions) { if (entityTypeName == null) throw new ArgumentNullException("entityTypeName"); if (createInstanceDelegate == null) throw new ArgumentNullException("createInstanceDelegate"); if (propertyDefinitions == null) throw new ArgumentNullException("propertyDefinitions"); // this.name = entityTypeName; this.category = category; this.repositoryVersion = version; this.createInstanceDelegate = createInstanceDelegate; this.propertyDefinitions = new List<EntityPropertyDefinition>(); // Sort property definitions: // EntityFieldDefinitions first, EntityInnerObjectsDefinition afterwards foreach (EntityPropertyDefinition propertyDef in propertyDefinitions) if (propertyDef is EntityFieldDefinition) this.propertyDefinitions.Add(propertyDef); foreach (EntityPropertyDefinition propertyDef in propertyDefinitions) if (propertyDef is EntityInnerObjectsDefinition) this.propertyDefinitions.Add(propertyDef); }
static CallbackHandler() { createInstanceCallback = new CreateInstanceDelegate(CreateInstanceStatic); destroyInstanceCallback = new DestroyInstanceDelegate(DestroyInstanceStatic); }
public TableMapper(SqliteDataReader reader, CreateInstanceDelegate instanceDelegate) { m_reader = reader; m_createInstanceDelegate = instanceDelegate; Orm.MappingType(typeof(T)); }
public void Register <T>(CreateInstanceDelegate creator) { KeyCreator.Add(typeof(T).FullName, creator); }