public virtual ConfigData GetConfigData(NameValueCollection form) { ConfigData data = new ConfigData { NeedProtect = this.NeedProtect }; foreach (PropertyInfo info in base.GetType().GetProperties()) { string str = form[info.Name] ?? "false"; ConfigElementAttribute customAttribute = (ConfigElementAttribute) Attribute.GetCustomAttribute(info, typeof(ConfigElementAttribute)); if (customAttribute != null) { if (!customAttribute.Nullable && (string.IsNullOrEmpty(str) || (str.Length == 0))) { data.IsValid = false; data.ErrorMsgs.Add(string.Format("{0}为必填项", customAttribute.Name)); } else if (!string.IsNullOrEmpty(str)) { try { Convert.ChangeType(str, info.PropertyType); } catch (FormatException) { data.IsValid = false; data.ErrorMsgs.Add(string.Format("{0}的输入格式不正确,请按正确格式输入", customAttribute.Name)); continue; } data.Add(info.Name, str); } } } return data; }
public virtual ConfigData GetConfigData(NameValueCollection form) { ConfigData data = new ConfigData(); data.NeedProtect = this.NeedProtect; foreach (PropertyInfo info in base.GetType().GetProperties()) { string str = form[info.Name] ?? "false"; ConfigElementAttribute customAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(info, typeof(ConfigElementAttribute)); if (customAttribute != null) { if (!customAttribute.Nullable && (string.IsNullOrEmpty(str) || (str.Length == 0))) { data.IsValid = false; data.ErrorMsgs.Add(string.Format("{0}为必填项", customAttribute.Name)); } else if (!string.IsNullOrEmpty(str)) { try { Convert.ChangeType(str, info.PropertyType); } catch (FormatException) { data.IsValid = false; data.ErrorMsgs.Add(string.Format("{0}的输入格式不正确,请按正确格式输入", customAttribute.Name)); goto Label_00EB; } data.Add(info.Name, str); Label_00EB :; } } } return(data); }
public virtual ConfigData GetConfigData(NameValueCollection form) { ConfigData configData = new ConfigData(); configData.NeedProtect = this.NeedProtect; PropertyInfo[] properties = base.GetType().GetProperties(); PropertyInfo[] array = properties; int i = 0; while (i < array.Length) { PropertyInfo propertyInfo = array[i]; string text = form[propertyInfo.Name] ?? "false"; ConfigElementAttribute configElementAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigElementAttribute)); if (configElementAttribute != null) { if (!configElementAttribute.Nullable && (string.IsNullOrEmpty(text) || text.Length == 0)) { configData.IsValid = false; configData.ErrorMsgs.Add(string.Format("{0}为必填项", configElementAttribute.Name)); } else if (!string.IsNullOrEmpty(text)) { try { Convert.ChangeType(text, propertyInfo.PropertyType); } catch (FormatException) { configData.IsValid = false; configData.ErrorMsgs.Add(string.Format("{0}的输入格式不正确,请按正确格式输入", configElementAttribute.Name)); goto IL_11B; } configData.Add(propertyInfo.Name, text); } } IL_11B: i++; continue; goto IL_11B; } return(configData); }