private IObjectConfiguration ConfigureObject(XmlNode configNode, IContainer container) { string objectName = configNode.Attributes["name"].Value; IObjectConfiguration objectConfig = GetObjectConfiguration(objectName, container); objectConfig.Name = objectName; if (configNode.Attributes["aop-config"] != null) { string sectionName = configNode.Attributes["aop-config"].Value; IEngine engine = NAspect.Framework.ApplicationContext.ConfigureFromSection(sectionName); objectConfig.AopEngine = engine; } if (configNode.Attributes["type"] != null) { string objectTypeString = configNode.Attributes["type"].Value; Type objectType = ResolveType(objectTypeString); objectConfig.Type = objectType; } if (configNode.Attributes["factory"] != null) { string factoryName = configNode.Attributes["factory"].Value; IFactoryConfiguration factoryConfig = GetFactoryConfiguration(factoryName, container); objectConfig.InstanceValue = factoryConfig; } //done if (configNode.Attributes["instance-mode"] != null) { string instanceModeString = configNode.Attributes["instance-mode"].Value; objectConfig.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString); } container.Configuration.AddObjectConfiguration(objectConfig); foreach (XmlNode objectNode in configNode) { #region property if (objectNode.Name == "property") { PropertyConfiguration propertyConfig = new PropertyConfiguration(); propertyConfig.Name = objectNode.Attributes["name"].Value; ConfigureElement(objectNode, propertyConfig, container, null); if (objectNode.Attributes["action"] != null) { string action = objectNode.Attributes["action"].Value; if (action == "Add") { propertyConfig.ListAction = ListAction.Add; } if (action == "Replace") { propertyConfig.ListAction = ListAction.Replace; } } objectConfig.PropertyConfigurations.Add(propertyConfig); } #endregion #region Ctor Parameter if (objectNode.Name == "ctor-parameter") { ParameterConfiguration parameterConfig = new ParameterConfiguration(); parameterConfig.Index = Convert.ToInt32(objectNode.Attributes["index"].Value); ConfigureElement(objectNode, parameterConfig, container, null); objectConfig.CtorParameterConfigurations.Add(parameterConfig); } #endregion } return(objectConfig); }
private void ConfigureElement(XmlNode node, ElementConfiguration config, IContainer container, Type valueType) { config.Type = valueType; if (node.Attributes["value"] != null) { string propertyValueString = node.Attributes["value"].Value; ValueConfiguration propertyValueConfig = new ValueConfiguration(); propertyValueConfig.Value = propertyValueString; config.Value = propertyValueConfig; if (node.Attributes["type-converter"] != null) { string typeConverterString = node.Attributes["type-converter"].Value; Type typeConverterType = ResolveType(typeConverterString); TypeConverter typeConverter = (TypeConverter)Activator.CreateInstance(typeConverterType); propertyValueConfig.TypeConverter = typeConverter; } if (node.Attributes["type"] != null) { string typeString = node.Attributes["type"].Value; Type type = ResolveType(typeString); config.Type = type; } } if (node.Attributes["object"] != null) { string propertyObjectName = node.Attributes["object"].Value; IObjectConfiguration propertyObjectConfig = GetObjectConfiguration(propertyObjectName, container); config.Value = propertyObjectConfig; //done if (node.Attributes["instance-mode"] != null) { string instanceModeString = node.Attributes["instance-mode"].Value; config.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString); } } if (node.Attributes["list"] != null) { string propertyListName = node.Attributes["list"].Value; IListConfiguration propertyListConfig = GetListConfiguration(propertyListName, container); config.Value = propertyListConfig; config.Type = typeof(IList); } if (node.Attributes["factory"] != null) { string itemFactoryName = node.Attributes["factory"].Value; IFactoryConfiguration propertyFactoryConfig = GetFactoryConfiguration(itemFactoryName, container); config.Value = propertyFactoryConfig; } }
private IFactoryConfiguration ConfigureFactory(XmlNode configNode, IContainer container) { string factoryName = configNode.Attributes["name"].Value; string factoryMethodName = configNode.Attributes["method"].Value; IFactoryConfiguration factoryConfig = GetFactoryConfiguration(factoryName, container); factoryConfig.Name = factoryName; factoryConfig.MethodName = factoryMethodName; if (configNode.Attributes["type"] != null) // { string objectTypeString = configNode.Attributes["type"].Value; Type objectType = ResolveType(objectTypeString); factoryConfig.Type = objectType; } else if (configNode.Attributes["object"] != null) //instance { string objectName = configNode.Attributes["object"].Value; IObjectConfiguration objectConfig = GetObjectConfiguration(objectName, container); factoryConfig.Object = objectConfig; } foreach (XmlNode factoryNode in configNode) { #region Parameter if (factoryNode.Name == "parameter") { ParameterConfiguration parameterConfig = new ParameterConfiguration(); parameterConfig.Index = Convert.ToInt32(factoryNode.Attributes["index"].Value); if (factoryNode.Attributes["value"] != null) { string propertyValueString = factoryNode.Attributes["value"].Value; ValueConfiguration propertyValueConfig = new ValueConfiguration(); if (factoryNode.Attributes["type"] != null) { //typed parameter string parameterTypeString = factoryNode.Attributes["type"].Value; Type parameterType = ResolveType(parameterTypeString); parameterConfig.Type = parameterType; propertyValueConfig.Value = Convert.ChangeType(propertyValueString, parameterConfig.Type); } else { //untyped parameter propertyValueConfig.Value = propertyValueString; // parameterConfig.UntypedStringValue = propertyValueString; parameterConfig.Type = null; } parameterConfig.Value = propertyValueConfig; } if (factoryNode.Attributes["object"] != null) { string parameterObjectName = factoryNode.Attributes["object"].Value; IObjectConfiguration propertyObjectConfig = GetObjectConfiguration(parameterObjectName, container); parameterConfig.Value = propertyObjectConfig; //done if (factoryNode.Attributes["instance-mode"] != null) { string instanceModeString = factoryNode.Attributes["instance-mode"].Value; parameterConfig.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString); } } factoryConfig.ParameterConfigurations.Add(parameterConfig); } #endregion } return(factoryConfig); }