private static AgileCreator GetCreator(Type type, object[] param) { Type[] paraTypeAry = null; if (param != null) { paraTypeAry = new Type[param.Length]; for (int i = 0; i < param.Length; i++) { if (param[i] != null) { paraTypeAry[i] = param[i].GetType(); } else { paraTypeAry[i] = typeof(object); } } } CreatorKey key = new CreatorKey(type, paraTypeAry); if (!DicCreator.ContainsKey(key)) { TypeBuilder tb = GetDynamicModule().DefineType(string.Concat(new object[] { "__dynamicCreator.", type.FullName, "_", key.GetHashCode() }), TypeAttributes.Public, 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); } 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); }