/// <summary> /// 创建实例,IL的实现,高效率 /// </summary> /// <param name="instanceType"></param> /// <returns></returns> public static object CreateInstance(this ConstructorInfo constructor, object[] args) { CreateInstanceMethod method = null; if (!_getCreateInstanceByConstructorMethods.TryGetValue(constructor, out method)) { if (method == null) { lock (_getCreateInstanceByConstructorMethods) { if (!_getCreateInstanceByConstructorMethods.TryGetValue(constructor, out method)) { if (method == null) { method = GenerateCreateInstanceMethod(constructor); _getCreateInstanceByConstructorMethods.Add(constructor, method); } } } } } var invoke = (Func <object[], object>)method.Invoke; return(invoke(args)); }
protected DelegateListClassPropertyBase(string name, GetListMethod getList, CreateInstanceMethod createInstance) : base(name) { Assert.IsNotNull(getList); m_GetList = getList; m_CreateInstance = createInstance ?? (c => default(TItem)); }
/// <summary> /// 创建实例,IL的实现,高效率 /// </summary> /// <param name="instanceType"></param> /// <returns></returns> public static object CreateInstance(this Type instanceType) { CreateInstanceMethod method = null; if (!_getCreateInstanceMethods.TryGetValue(instanceType, out method)) { if (method == null) { lock (_getCreateInstanceMethods) { if (!_getCreateInstanceMethods.TryGetValue(instanceType, out method)) { if (method == null) { method = GenerateCreateInstanceMethod(instanceType); _getCreateInstanceMethods.Add(instanceType, method); } } } } } var invoke = (Func <object>)method.Invoke; return(invoke()); }
private T CreateResourceInstance() { try { CreateInstanceMethod _createInstanceCaller = new CreateInstanceMethod(this.ResourceHandle.CreateInstance); IAsyncResult _asyncResult = _createInstanceCaller.BeginInvoke(null, null); if (_asyncResult.AsyncWaitHandle.WaitOne(this.ConnectTimeout)) { return(_createInstanceCaller.EndInvoke(_asyncResult)); } } catch { } return(null); }
public static void RegisterElementType(Type elementType, CreateInstanceMethod method, string displayName) { if (!g_registeredElements.ContainsKey(elementType)) { CompendiumElementRegistrationInfo info = new CompendiumElementRegistrationInfo { Index = g_registeredIndex, ElementType = elementType, Method = method, DisplayName = displayName }; g_registeredElements.Add(elementType, info); g_registeredIndex++; } else { Console.WriteLine("That Compendium Page Element has already been registered! " + elementType.ToString()); } }
public static void RegisterElementType(Type elementType, CreateInstanceMethod method, string displayName) { if (!g_registeredElements.ContainsKey(elementType)) { var info = new CompendiumElementRegistrationInfo { Index = g_registeredIndex, ElementType = elementType, Method = method, DisplayName = displayName }; g_registeredElements.Add(elementType, info); g_registeredIndex++; } else { Console.WriteLine("That Compendium Page Element has already been registered! " + elementType); } }
public StructMutableContainerListProperty(string name, GetValueMethod getValue, SetValueMethod setValue, CreateInstanceMethod createInstanceMethod = null) : base(name, getValue, setValue, createInstanceMethod) { }
public StructListProperty(string name, GetValueMethod getValue, SetValueMethod setValue, CreateInstanceMethod createInstance = null) : base(name, getValue, setValue) { m_CreateInstanceMethod = createInstance ?? DefaultCreateInstance; }
public StructListStructProperty(string name, GetListMethod getList, CreateInstanceMethod createInstance = null) : base(name, getList, createInstance) { }
protected DelegateListStructPropertyBase(string name, GetListMethod getList, CreateInstanceMethod createInstance) : base(name) { m_GetList = getList; m_CreateInstance = createInstance ?? ((ref TContainer c) => default(TItem)); }
public ClassListClassProperty(string name, GetListMethod getList, CreateInstanceMethod createInstance = null) : base(name, getList, createInstance) { }
public EnumListProperty(string name, GetValueMethod getValue, SetValueMethod setValue, CreateInstanceMethod createInstance = null) : base(name, getValue, setValue, createInstance) { Assert.IsTrue(typeof(TItem).IsEnum); }