protected override bool Add(string regName, BasePlugInAttribute attribute, Type type) { Attribute instanceAttr = Attribute.GetCustomAttribute(type, typeof(InstancePlugInAttribute)); if (instanceAttr != null) { BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; FieldInfo fieldInfo = type.GetField("Instance", flags); if (fieldInfo == null) { fieldInfo = type.GetField("INSTANCE", flags); if (fieldInfo == null) { return(false); } } object value = ObjectUtil.GetStaticValue(fieldInfo); if (value == null) { return(false); } ICacheDependency dependency = CacheUtil.GetDependency(type, null); if (dependency == null) { dependency = AlwaysDependency.Dependency; } return(AddInstance(regName, attribute, value, dependency) != null); } else { return(base.Add(regName, attribute, type)); } }
internal ErrorPlugInInfo(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType) { RegName = attribute.GetRegName(type); Type = type.ToString(); AssemblyName = type.Assembly.FullName; Error = errorType; }
/// <summary> /// Initializes a new instance of the InstanceRegItem class. /// </summary> public InstanceRegItem(string regName, BasePlugInAttribute attribute, object instance, ICacheDependency dependency) : base(regName, attribute) { fInstance = instance; fInstanceType = instance.GetType(); Dependency = dependency; }
public bool AddCodePlugIn(BasePlugInAttribute attribute, Type type) { TkDebug.AssertArgumentNull(attribute, "attribute", this); TkDebug.AssertArgumentNull(type, "type", this); BasePlugInFactory factory = GetFactory(attribute.FactoryName); return(factory.Add(attribute, type)); }
private void TryAddSection(string regName, Type type, BasePlugInAttribute attribute) { if (attribute is FactoryDefaultValueAttribute factoryAttr) { AddSection(factoryAttr.SectionName, factoryAttr.ConfigFactoryName); } else if (attribute is DefaultValueAttribute) { fObjectConfig.Add(regName, type); } }
public bool Add(BasePlugInAttribute attribute, Type type) { TkDebug.AssertArgumentNull(attribute, "attribute", this); TkDebug.AssertArgumentNull(type, "type", this); TkDebug.Assert(attribute.FactoryName == Name, string.Format(ObjectUtil.SysCulture, "调用错误,Attribute的工厂名{0}和当前工厂的不一致", attribute.FactoryName), this); string regName = attribute.GetRegName(type); return(Add(regName, attribute, type)); }
private void AddAdditionObj(string regName, Type type, BasePlugInAttribute attr) { if (ObjectUtil.IsSubType(typeof(EvaluateAdditionType), type)) { EvaluateAdditionType add = CreateInstance <EvaluateAdditionType>(regName); EvaluatorUtil.AddAdditionObj(add.CreateAdditionObject()); } else { string name = type.Name; EvaluatorUtil.AddAdditionObj((name, type)); } }
protected virtual bool Add(string regName, BasePlugInAttribute attribute, Type type) { lock (this) { if (!Contains(regName)) { CodeRegItem regItem = new CodeRegItem(regName, attribute, type); InternalAddPlugIn(regName, regItem); return(true); } return(false); } }
internal InstanceRegItem AddInstance(string regName, BasePlugInAttribute attribute, object instance, ICacheDependency dependency) { lock (this) { if (!Contains(regName)) { InstanceRegItem instanceRegItem = new InstanceRegItem(regName, attribute, instance, dependency); fInstancePlugIns.Add(regName, instanceRegItem); return(instanceRegItem); } return(null); } }
//internal void AddElements(ObjectElementInfo elements, Type type, // PropertyInfo property, string modelName, DynamicElementAttribute dynamic) //{ // EnumableCodePlugIn((regName, regType, attr) => // { // ObjectElementAttribute objectAttr = attr.Convert<BaseObjectElementAttribute>() // .ConvertTo(regName, regType, dynamic); // elements.Add(type, property, objectAttr, modelName); // }); //} //internal void AddElements(Dictionary<string, ObjectElementAttribute> dictionary, string factoryName) //{ // DynamicElementAttribute dynamic = new DynamicElementAttribute(factoryName); // EnumableCodePlugIn((regName, regType, attr) => // { // ObjectElementAttribute objectAttr = attr.Convert<BaseObjectElementAttribute>() // .ConvertTo(regName, regType, dynamic); // dictionary.Add(regName, objectAttr); // }); //} protected override bool Add(string regName, BasePlugInAttribute attribute, Type type) { BaseObjectElementAttribute elementAttr = attribute.Convert <BaseObjectElementAttribute>(); string newRegName; if (SupportVersion) { VersionRegName version = new VersionRegName(regName, GetVersion(elementAttr)); newRegName = version.WriteJson(); } else { newRegName = regName; } var result = base.Add(newRegName, attribute, type); if (result) { fConfigData.Add(this, regName, elementAttr, type); } return(result); }
internal bool InternalAddCodePlugIn(BaseGlobalVariable globalVariable, BasePlugInAttribute attribute, Type type) { BasePlugInFactory factory = ObjectUtil.TryGetValue(fAllFactories, attribute.FactoryName); if (factory == null) { globalVariable.AddCodeError(attribute, type, PlugInErrorType.NoFactory); return(false); } bool result = factory.Add(attribute, type); if (!result) { globalVariable.AddCodeError(attribute, type, PlugInErrorType.Duplicate); } else { TkTrace.LogInfo($"在工程[{factory.Description}]中添加注册名为[{attribute.GetRegName(type)}]类型[{type}]"); } return(result); }
internal void AddCodeError(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType) { fPlugInErrorLog.AddCodeError(attribute, type, errorType); }
protected BaseRegItem(string regName, BasePlugInAttribute attribute) { RegName = regName; Attribute = attribute; }
internal void AddCodeError(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType) { Code.Add(new ErrorPlugInInfo(attribute, type, errorType)); }
public CodeRegItem(string regName, BasePlugInAttribute attribute, Type regType) : base(regName, attribute) { RegType = regType; }