Exemplo n.º 1
0
 private static void SetObjectSetting(ObjectServiceBase objectService, IObjectSetting objectSetting, object instance)
 {
     if(objectSetting.SettingSet == null || string.IsNullOrEmpty(objectSetting.SettingSet.TypeName)) {
         return;
     }
     var typeName = objectService.GetTypeNameInternal(objectSetting.SettingSet.TypeName, objectSetting.Namespace);
     var setting = (IConfigSettingElement)TypeHelper.CreateObject(typeName, typeof(IConfigSettingElement), false);
     setting = GetSetting(objectService, objectSetting, setting);
     if (setting == null) {
         return;
     }
     if (instance is ISettingRequired) {
         ((ISettingRequired)instance).Setting = setting;
     }
     var settingType = setting.GetType();
     var iinitializableType = typeof (IInitializable<>).MakeGenericType(settingType);
     if (iinitializableType.IsInstanceOfType(instance)) {
         var mi = iinitializableType.GetMethod("Init");
         object returnValue;
         TypeHelper.TryInvoke(instance, mi, out returnValue, false, setting);
     }
     var isettingRequiredType = typeof(ISettingRequired<>).MakeGenericType(settingType);
     if(isettingRequiredType.IsInstanceOfType(instance)) {
         var property = isettingRequiredType.GetProperty("Setting");
         try {
             property.SetValue(instance, setting, null);
         } catch { }
     }
 }
Exemplo n.º 2
0
 private static IConfigSettingElement GetSetting(ObjectServiceBase objectService, IObjectSetting objectSetting, IConfigSettingElement setting)
 {
     setting.ConfigSetting = objectService.GetObjectSettingInternal(objectSetting);
     var handlerName = objectSetting.SettingSet.Value;
     if(!string.IsNullOrEmpty(handlerName)) {
         var handler = objectService.GetOrCreateObject<ISettingHandler>(handlerName);
         if(handler != null) {
             setting = handler.GetSetting(setting);
         }
     }
     return setting;
 }
Exemplo n.º 3
0
            private static IConfigSettingElement GetSetting(ObjectServiceBase objectService, IObjectSetting objectSetting, IConfigSettingElement setting)
            {
                setting.ConfigSetting = objectService.GetObjectSettingInternal(objectSetting);
                var handlerName = objectSetting.SettingSet.Value;

                if (!string.IsNullOrEmpty(handlerName))
                {
                    var handler = objectService.GetOrCreateObject <ISettingHandler>(handlerName);
                    if (handler != null)
                    {
                        setting = handler.GetSetting(setting);
                    }
                }
                return(setting);
            }
Exemplo n.º 4
0
            private static void SetObjectSetting(ObjectServiceBase objectService, IObjectSetting objectSetting, object instance)
            {
                if (objectSetting.SettingSet == null || string.IsNullOrEmpty(objectSetting.SettingSet.TypeName))
                {
                    return;
                }
                var typeName = objectService.GetTypeNameInternal(objectSetting.SettingSet.TypeName, objectSetting.Namespace);
                var setting  = (IConfigSettingElement)TypeHelper.CreateObject(typeName, typeof(IConfigSettingElement), false);

                setting = GetSetting(objectService, objectSetting, setting);
                if (setting == null)
                {
                    return;
                }
                if (instance is ISettingRequired)
                {
                    ((ISettingRequired)instance).Setting = setting;
                }
                var settingType        = setting.GetType();
                var iinitializableType = typeof(IInitializable <>).MakeGenericType(settingType);

                if (iinitializableType.IsInstanceOfType(instance))
                {
                    var    mi = iinitializableType.GetMethod("Init");
                    object returnValue;
                    TypeHelper.TryInvoke(instance, mi, out returnValue, false, setting);
                }
                var isettingRequiredType = typeof(ISettingRequired <>).MakeGenericType(settingType);

                if (isettingRequiredType.IsInstanceOfType(instance))
                {
                    var property = isettingRequiredType.GetProperty("Setting");
                    try {
                        property.SetValue(instance, setting, null);
                    } catch { }
                }
            }
 public ObjectBuilderInternal(ObjectServiceBase objectService)
 {
     this.ObjectService             = objectService;
     this.ObjectSettingDependencies = new Dictionary <IObjectSetting, bool>();
 }
 public ObjectBuilderInternal(ObjectServiceBase objectService)
 {
     this.ObjectService = objectService;
     this.ObjectSettingDependencies = new Dictionary<IObjectSetting, bool>();
 }