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)); } }
private void CachePlugInObject(string regName, object instance) { Type objType = instance.GetType(); bool isCache = CacheUtil.IsCacheInstance(objType); if (!isCache) { return; } ICacheDependency dependency = CacheUtil.GetDependency(objType, instance); if (dependency == null) { dependency = AlwaysDependency.Dependency; } Cache.AddCacheInstance(regName, instance, dependency, false); }