/// <summary> /// GetCreator 动态产生一个派生自AgileCreator的类,并生成其实例 /// </summary> private static AgileCreator GetCreator(Type type, Object[] param) { Type[] paramTypeAry = null; if (param != null) { paramTypeAry = new Type[param.Length]; for (int i = 0; i < param.Length; i++) { if (param[i] != null) { paramTypeAry[i] = param[i].GetType(); } else { paramTypeAry[i] = typeof(object); } } } CreatorKey key = new CreatorKey(type, paramTypeAry); if (!DicCreator.ContainsKey(key)) { ModuleBuilder module = GetDynamicModule(); TypeBuilder tb = module.DefineType("__dynamicCreator." + type.FullName + "_" + key.GetHashCode(), TypeAttributes.Public | TypeAttributes.Class, typeof(AgileCreator)); CreateMethod(tb, type, param); DicCreator.Add(key, (AgileCreator)Activator.CreateInstance(tb.CreateType())); } return(DicCreator[key]); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj.GetType() != typeof(CreatorKey)) { return(false); } #region Old CreatorKey key = (CreatorKey)obj; if (key.targetType != this.targetType) { return(false); } if ((key.paramTypeArray == null) && (this.paramTypeArray != null)) { return(false); } if ((key.paramTypeArray != null) && (this.paramTypeArray == null)) { return(false); } if (key.paramTypeArray.Length != this.paramTypeArray.Length) { return(false); } for (int i = 0; i < this.paramTypeArray.Length; i++) { if (this.paramTypeArray[i] != key.paramTypeArray[i]) { return(false); } } return(true); #endregion #region new //return (this.GetHashCode() == obj.GetHashCode()) ; #endregion }
/// <summary> /// GetCreator 动态产生一个派生自AgileCreator的类,并生成其实例 /// </summary> private static AgileCreator GetCreator(Type type, Object[] param) { Type[] paramTypeAry = null; if (param != null) { paramTypeAry = new Type[param.Length]; for (int i = 0; i < param.Length; i++) { if (param[i] != null) { paramTypeAry[i] = param[i].GetType(); } else { paramTypeAry[i] = typeof(object); } } } CreatorKey key = new CreatorKey(type, paramTypeAry); if (!DicCreator.ContainsKey(key)) { ModuleBuilder module = GetDynamicModule(); TypeBuilder tb = module.DefineType("__dynamicCreator." + type.FullName + "_" + key.GetHashCode(), TypeAttributes.Public | TypeAttributes.Class, typeof(AgileCreator)); CreateMethod(tb, type, param); DicCreator.Add(key, (AgileCreator)Activator.CreateInstance(tb.CreateType())); } return DicCreator[key]; }