private void ObjectBuilderOnObjectCreated(IObjectBuilderContext builderContext) { var instance = builderContext.ObjectInstance; if (instance == null) { return; } this.ObjectMappingInternal(builderContext, instance); }
private void ObjectBuilderOnObjectCreating(IObjectBuilderContext builderContext) { var instance = builderContext.Items[typeof(ObjectMapperExtender)]; if (instance == null) { return; } this.ObjectMappingInternal(builderContext, instance); builderContext.ObjectInstance = instance; }
protected override void CreateObjectInternal(IObjectBuilderContext ctx, params object[] args) { var attribute = ctx.ObjectDescription.Items[typeof(RemotingServiceAttribute)] as RemotingServiceAttribute; var objectType = ctx.ObjectDescription.ObjectType; var uri = attribute.Url; var contentType = attribute.ContentType; var factory = this.ObjectService.GetObject <IHttpRealProxyFactory>(); var instance = factory.GetProxyObject(objectType, uri, contentType); ctx.ObjectInstance = instance; }
protected override void CreateObjectInternal(IObjectBuilderContext ctx, params object[] args) { var attribute = ctx.ObjectDescription.Items[typeof(DataServiceAttribute)] as DataServiceAttribute; var groupName = attribute?.GroupName; if (string.IsNullOrEmpty(groupName)) { groupName = ctx.ObjectDescription.ObjectType.FullName; } if (!string.IsNullOrEmpty(groupName)) { groupName += "."; } var instance = TypeHelper.CreateServiceDispatchProxy(ctx.ObjectDescription.ObjectType, new DataServiceWrapper { GroupName = groupName }); ctx.ObjectInstance = instance; }
private void ObjectServiceOnObjectCreated(IObjectBuilderContext builderContext) { var instance = builderContext.ObjectInstance; if(instance == null) { return; } if(RemotingServices.IsTransparentProxy(instance)) { return; } var objectService = this.ObjectService as ObjectServiceBase; if(objectService == null) { return; } SetObjectSetting(objectService, builderContext.ObjectSetting, instance); if(instance is IInitializable) { ((IInitializable)instance).Init(); } }
private void ObjectServiceOnObjectCreated(IObjectBuilderContext ctx) { //处理实现IInitializable<T>的类型 var instance = ctx.ObjectInstance; if (instance == null) { return; } var type = instance.GetType(); var interfaces = type.GetInterfaces(); if (interfaces != null) { var objectService = ctx.ObjectService; foreach (var intf in interfaces) { if (!intf.IsGenericType) { continue; } if (intf.GetGenericTypeDefinition() != typeof(IInitializable <>)) { continue; } var args = intf.GetGenericArguments(); var settingType = args[0]; var settingInstance = objectService.GetObject(settingType); var method = intf.GetMethod("Init"); if (method != null) { method.Invoke(instance, new object[] { settingInstance }); } } } (instance as IInitializable)?.Init(); }
protected override void CreateObjectInternal(IObjectBuilderContext ctx, params object[] args) { if (!(ctx.ObjectDescription.Items[typeof(SettingObjectAttribute)] is SettingObjectAttribute attribute)) { return; } var xpath = attribute.XPath; var type = attribute.OwnerType; if (string.IsNullOrEmpty(xpath)) { xpath = type.FullName.ToLowerInvariant(); } var objectService = (IObjectServiceInternal)ctx.ObjectService; var setting = objectService.ConfigSetting.GetChildSetting(xpath); if (setting == null && attribute.Required) { throw new Exception($"必须为 {type.FullName} 配置节点:{xpath}"); } IConfigSettingElement element; if (type.IsInterface) //动态生成 { element = ConfigSettingElement.CreateProxy(setting, type); } else { element = (IConfigSettingElement)TypeHelper.CreateObject(type, typeof(IConfigSettingElement), false, args); } if (element != null) { element.ConfigSetting = setting; } ctx.ObjectInstance = element; }
protected virtual void OnObjectCreated(IObjectBuilderContext ctx) { this.ObjectCreated?.Invoke(ctx); }
private void ObjectMappingInternal(IObjectBuilderContext builderContext, object instance) { var dict = builderContext.Items[typeof(IObjectMapper)]; if (dict == null || (!(dict is IDataRecord) && !(dict is IDictionary))) { return; } if(instance is IEntityInitialize) { ((IEntityInitialize)instance).InitValues(dict is IDataRecord ? ((IDataRecord)dict).ToDictionary() : (IDictionary)dict); return; } var setting = builderContext.ObjectSetting.ConfigSetting; var mapSetting = (IObjectMapSetting)setting.ToCachedSetting<ObjectMapSetting>("objectMap"); if (mapSetting == null) { return; } IEqualityComparer<string> comparer = null; if(mapSetting.IgnoreCase) { comparer = StringComparer.InvariantCultureIgnoreCase; } var dictionary = dict is IDataRecord ? ((IDataRecord)dict).ToDictionary(comparer) : ((IDictionary)dict).ToDictionary(comparer); var excludeProperties = new List<string>(); var excludeString = mapSetting.ExcludeProperties; if (excludeString != null) { excludeProperties.AddRange(excludeString.Split(',')); } var includeProperties = new List<string>(); var includeString = mapSetting.IncludeProperties; includeProperties.AddRange(includeString.Split(',')); var properties = mapSetting.Properties; if (properties != null && properties.Length > 0) { var translatorName = mapSetting.TypeTranslatorName; ITypeTranslator translator = null; if(!string.IsNullOrEmpty(translatorName)) { translator = this.ObjectService.GetOrCreateObject<ITypeTranslator>(translatorName); } var propertyInitilize = instance as IPropertyInitialize; foreach (var property in properties) { var columnName = property.ColumnName; if(!dictionary.ContainsKey(columnName)) { continue; } var value = dictionary[columnName]; if(propertyInitilize != null) { propertyInitilize.SetValue(property.PropertyName, value); } else if (value != null) { if(translator != null) { ReflectionHelper.SetPropertyValue(instance, property.PropertyName, (x, p) => translator.Translate(value, p.MemberType, null)); } else { ReflectionHelper.SetPropertyValue(instance, property.PropertyName, value); } } excludeProperties.Add(columnName); includeProperties.Remove(columnName); } } if (includeProperties.Count > 0) { ObjectMapper.RefectionMapping(instance, dictionary, excludeProperties, includeProperties); } }
private void ObjectMappingInternal(IObjectBuilderContext builderContext, object instance) { var dict = builderContext.Items[typeof(IObjectMapper)]; if (dict == null || (!(dict is IDataRecord) && !(dict is IDictionary))) { return; } if (instance is IEntityInitialize) { ((IEntityInitialize)instance).InitValues(dict is IDataRecord ? ((IDataRecord)dict).ToDictionary() : (IDictionary)dict); return; } var setting = builderContext.ObjectSetting.ConfigSetting; var mapSetting = (IObjectMapSetting)setting.ToCachedSetting <ObjectMapSetting>("objectMap"); if (mapSetting == null) { return; } IEqualityComparer <string> comparer = null; if (mapSetting.IgnoreCase) { comparer = StringComparer.InvariantCultureIgnoreCase; } var dictionary = dict is IDataRecord ? ((IDataRecord)dict).ToDictionary(comparer) : ((IDictionary)dict).ToDictionary(comparer); var excludeProperties = new List <string>(); var excludeString = mapSetting.ExcludeProperties; if (excludeString != null) { excludeProperties.AddRange(excludeString.Split(',')); } var includeProperties = new List <string>(); var includeString = mapSetting.IncludeProperties; includeProperties.AddRange(includeString.Split(',')); var properties = mapSetting.Properties; if (properties != null && properties.Length > 0) { var translatorName = mapSetting.TypeTranslatorName; ITypeTranslator translator = null; if (!string.IsNullOrEmpty(translatorName)) { translator = this.ObjectService.GetOrCreateObject <ITypeTranslator>(translatorName); } var propertyInitilize = instance as IPropertyInitialize; foreach (var property in properties) { var columnName = property.ColumnName; if (!dictionary.ContainsKey(columnName)) { continue; } var value = dictionary[columnName]; if (propertyInitilize != null) { propertyInitilize.SetValue(property.PropertyName, value); } else if (value != null) { if (translator != null) { ReflectionHelper.SetPropertyValue(instance, property.PropertyName, (x, p) => translator.Translate(value, p.MemberType, null)); } else { ReflectionHelper.SetPropertyValue(instance, property.PropertyName, value); } } excludeProperties.Add(columnName); includeProperties.Remove(columnName); } } if (includeProperties.Count > 0) { ObjectMapper.RefectionMapping(instance, dictionary, excludeProperties, includeProperties); } }
void IObjectServiceInternal.OnObjectCreated(IObjectBuilderContext ctx) => this.OnObjectCreated(ctx);
protected virtual void CreateObjectInternal(IObjectBuilderContext ctx, params object[] args) { var instance = BuildObject(ctx.ObjectService, ctx.ObjectDescription, ctx.Items, args); ctx.ObjectInstance = instance; }
protected virtual void OnObjectCreated(IObjectBuilderContext ctx) { var objectService = (IObjectServiceInternal)ctx.ObjectService; objectService?.OnObjectCreated(ctx); }
protected virtual object OnObjectCreating(IObjectBuilderContext ctx) { if (this.ObjectCreating != null) { this.ObjectCreating(ctx); } return ctx.ObjectInstance; }