internal void AddProperty(ConfigPropertyObject propertyObject) { if (ConfigValues.ContainsKey(propertyObject.Name) == false) { //add Property to ConfigValues ConfigValues.Add(propertyObject.Name, propertyObject); //update also definition just for consistency if (m_configWrapperDefinition != null) { m_configWrapperDefinition.AddProperty(propertyObject); } } }
/// <summary> /// This method creates ConfigWrapperDefinition based on the given configType. In case in config files written in C# it will use Properties as Config parameters. /// In case of Java it will scan for pairs of getters and setters, and if it will find one it will create a property for it. For example void setTest(string value) and string getTest() /// will generate property 'string Test' /// </summary> /// <param name="configType"></param> /// <returns></returns> internal static ConfigWrapperDefinition CreateConfigWrapperDefinition(Type configType) { ConfigWrapperDefinition configWrapperDefinition = null; if (configType != null) { bool isJava = CheckIfJavaType(configType); configWrapperDefinition = new ConfigWrapperDefinition(isJava, configType.FullName); if (isJava == false) { System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(configType); configWrapperDefinition.AddProperties(properties); } else { //check for java if there are any java getters String getterPrefix = "get"; String setterPrefix = "set"; String getterPropertyPrefix = "get_"; // .net style getter generated for properties MethodInfo[] methods = configType.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (MethodInfo method in methods) { if (method.Name.StartsWith(getterPrefix, StringComparison.InvariantCulture) == true && method.Name.StartsWith(getterPropertyPrefix, StringComparison.InvariantCulture) == false) { String propertyName = method.Name.Substring(getterPrefix.Length); Type propertyType = method.ReturnParameter.ParameterType; //check if there is any corresponding set method for this property if (methods.Any(item => item.Name.Equals(setterPrefix + propertyName, StringComparison.CurrentCulture))) { //check if setter has one input of the same type as the getter return type MethodInfo setter = configType.GetMethod(setterPrefix + propertyName, BindingFlags.Public | BindingFlags.Instance, null, new Type[] { propertyType }, null); if (setter != null) { //TODO: Description for hava config values string propertyDescription = propertyName; //finally add the property configWrapperDefinition.AddProperty(propertyName, method.ReturnParameter.ParameterType.FullName, method.ReturnParameter.ParameterType.AssemblyQualifiedName, propertyName, propertyDescription); } } } } } } return(configWrapperDefinition); }
/// <summary> /// This method creates ConfigWrapperDefinition based on the given configType. In case in config files written in C# it will use Properties as Config parameters. /// In case of Java it will scan for pairs of getters and setters, and if it will find one it will create a property for it. For example void setTest(string value) and string getTest() /// will generate property 'string Test' /// </summary> /// <param name="configType"></param> /// <returns></returns> internal static ConfigWrapperDefinition CreateConfigWrapperDefinition(Type configType) { ConfigWrapperDefinition configWrapperDefinition = null; if (configType != null) { bool isJava = CheckIfJavaType(configType); configWrapperDefinition = new ConfigWrapperDefinition(isJava, configType.FullName); if (isJava == false) { System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(configType); configWrapperDefinition.AddProperties(properties); } else { //check for java if there are any java getters String getterPrefix = "get"; String setterPrefix = "set"; String getterPropertyPrefix = "get_"; // .net style getter generated for properties MethodInfo[] methods = configType.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (MethodInfo method in methods) { if (method.Name.StartsWith(getterPrefix, StringComparison.InvariantCulture) == true && method.Name.StartsWith(getterPropertyPrefix, StringComparison.InvariantCulture) == false) { String propertyName = method.Name.Substring(getterPrefix.Length); Type propertyType = method.ReturnParameter.ParameterType; //check if there is any corresponding set method for this property if (methods.Any(item => item.Name.Equals(setterPrefix + propertyName, StringComparison.CurrentCulture))) { //check if setter has one input of the same type as the getter return type MethodInfo setter = configType.GetMethod(setterPrefix + propertyName, BindingFlags.Public | BindingFlags.Instance, null, new Type[] { propertyType }, null); if (setter != null) { //TODO: Description for hava config values string propertyDescription = propertyName; //finally add the property configWrapperDefinition.AddProperty(propertyName, method.ReturnParameter.ParameterType.FullName, method.ReturnParameter.ParameterType.AssemblyQualifiedName, propertyName, propertyDescription); } } } } } } return configWrapperDefinition; }