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);
        }
        internal virtual XmlDocument GetMetaData()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<xml></xml>");
            foreach (PropertyInfo info in base.GetType().GetProperties())
            {
                ConfigElementAttribute customAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(info, typeof(ConfigElementAttribute));
                if (customAttribute != null)
                {
                    AppendAttrubiteNode(doc, customAttribute, info);
                }
            }
            return(doc);
        }
        public virtual IList <string> GetHiddenPartConfigNames()
        {
            PropertyInfo[] properties = base.GetType().GetProperties();
            IList <string> list       = new List <string>();

            PropertyInfo[] array = properties;
            foreach (PropertyInfo propertyInfo in array)
            {
                ConfigElementAttribute configElementAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigElementAttribute));
                if (configElementAttribute != null && configElementAttribute.HiddenPart)
                {
                    list.Add(propertyInfo.Name);
                }
            }
            return(list);
        }
 protected virtual void InitConfig(XmlNode configXml)
 {
     PropertyInfo[] properties = base.GetType().GetProperties();
     foreach (PropertyInfo info in properties)
     {
         ConfigElementAttribute customAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(info, typeof(ConfigElementAttribute));
         if (customAttribute != null)
         {
             XmlNode node = configXml.SelectSingleNode(info.Name);
             if (((node != null) && !string.IsNullOrEmpty(node.InnerText)) && (node.InnerText.Length > 0))
             {
                 info.SetValue(this, Convert.ChangeType(node.InnerText, info.PropertyType), null);
             }
         }
     }
 }
 protected virtual void InitConfig(XmlNode configXml)
 {
     PropertyInfo[] properties = base.GetType().GetProperties();
     PropertyInfo[] array      = properties;
     foreach (PropertyInfo propertyInfo in array)
     {
         ConfigElementAttribute configElementAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigElementAttribute));
         if (configElementAttribute != null)
         {
             XmlNode xmlNode = configXml.SelectSingleNode(propertyInfo.Name);
             if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText) && xmlNode.InnerText.Length > 0)
             {
                 propertyInfo.SetValue(this, Convert.ChangeType(xmlNode.InnerText, propertyInfo.PropertyType), null);
             }
         }
     }
 }
        internal virtual XmlDocument GetMetaData()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.XmlResolver = null;
            xmlDocument.LoadXml("<xml></xml>");
            PropertyInfo[] properties = base.GetType().GetProperties();
            PropertyInfo[] array      = properties;
            foreach (PropertyInfo propertyInfo in array)
            {
                ConfigElementAttribute configElementAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigElementAttribute));
                if (configElementAttribute != null)
                {
                    ConfigablePlugin.AppendAttrubiteNode(xmlDocument, configElementAttribute, propertyInfo);
                }
            }
            return(xmlDocument);
        }
Beispiel #7
0
        internal virtual XmlDocument GetMetaData()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml("<xml></xml>");
            PropertyInfo[] properties = base.GetType().GetProperties();
            PropertyInfo[] array      = properties;
            for (int i = 0; i < array.Length; i++)
            {
                PropertyInfo           propertyInfo           = array[i];
                ConfigElementAttribute configElementAttribute = (ConfigElementAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ConfigElementAttribute));
                if (configElementAttribute != null)
                {
                    ConfigablePlugin.AppendAttrubiteNode(xmlDocument, configElementAttribute, propertyInfo);
                }
            }
            return(xmlDocument);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        private static void AppendAttrubiteNode(XmlDocument doc, ConfigElementAttribute att, PropertyInfo property)
        {
            XmlNode      xmlNode      = doc.CreateElement("att");
            XmlAttribute xmlAttribute = doc.CreateAttribute("Property");

            xmlAttribute.Value = property.Name;
            xmlNode.Attributes.Append(xmlAttribute);
            XmlAttribute xmlAttribute2 = doc.CreateAttribute("Name");

            xmlAttribute2.Value = (string.IsNullOrEmpty(att.Name) ? property.Name : att.Name);
            xmlNode.Attributes.Append(xmlAttribute2);
            XmlAttribute xmlAttribute3 = doc.CreateAttribute("Description");

            xmlAttribute3.Value = att.Description;
            xmlNode.Attributes.Append(xmlAttribute3);
            XmlAttribute xmlAttribute4 = doc.CreateAttribute("Nullable");

            xmlAttribute4.Value = att.Nullable.ToString();
            xmlNode.Attributes.Append(xmlAttribute4);
            XmlAttribute xmlAttribute5 = doc.CreateAttribute("InputType");

            xmlAttribute5.Value = ((int)att.InputType).ToString();
            xmlNode.Attributes.Append(xmlAttribute5);
            if (att.Options != null && att.Options.Length > 0)
            {
                XmlNode  xmlNode2 = doc.CreateElement("Options");
                string[] options  = att.Options;
                for (int i = 0; i < options.Length; i++)
                {
                    string  innerText = options[i];
                    XmlNode xmlNode3  = doc.CreateElement("Item");
                    xmlNode3.InnerText = innerText;
                    xmlNode2.AppendChild(xmlNode3);
                }
                xmlNode.AppendChild(xmlNode2);
            }
            doc.SelectSingleNode("xml").AppendChild(xmlNode);
        }
        private static void AppendAttrubiteNode(XmlDocument doc, ConfigElementAttribute att, PropertyInfo property)
        {
            XmlNode      newChild = doc.CreateElement("att");
            XmlAttribute node     = doc.CreateAttribute("Property");

            node.Value = property.Name;
            newChild.Attributes.Append(node);
            XmlAttribute attribute2 = doc.CreateAttribute("Name");

            attribute2.Value = string.IsNullOrEmpty(att.Name) ? property.Name : att.Name;
            newChild.Attributes.Append(attribute2);
            XmlAttribute attribute3 = doc.CreateAttribute("Description");

            attribute3.Value = att.Description;
            newChild.Attributes.Append(attribute3);
            XmlAttribute attribute4 = doc.CreateAttribute("Nullable");

            attribute4.Value = att.Nullable.ToString();
            newChild.Attributes.Append(attribute4);
            XmlAttribute attribute5 = doc.CreateAttribute("InputType");

            attribute5.Value = ((int)att.InputType).ToString();
            newChild.Attributes.Append(attribute5);
            if ((att.Options != null) && (att.Options.Length > 0))
            {
                XmlNode node2 = doc.CreateElement("Options");
                foreach (string str in att.Options)
                {
                    XmlNode node3 = doc.CreateElement("Item");
                    node3.InnerText = str;
                    node2.AppendChild(node3);
                }
                newChild.AppendChild(node2);
            }
            doc.SelectSingleNode("xml").AppendChild(newChild);
        }
Beispiel #11
0
 static void AppendAttrubiteNode(XmlDocument doc, ConfigElementAttribute att, PropertyInfo property)
 {
     XmlNode newChild = doc.CreateElement("att");
     XmlAttribute node = doc.CreateAttribute("Property");
     node.Value = property.Name;
     newChild.Attributes.Append(node);
     XmlAttribute attribute2 = doc.CreateAttribute("Name");
     attribute2.Value = string.IsNullOrEmpty(att.Name) ? property.Name : att.Name;
     newChild.Attributes.Append(attribute2);
     XmlAttribute attribute3 = doc.CreateAttribute("Description");
     attribute3.Value = att.Description;
     newChild.Attributes.Append(attribute3);
     XmlAttribute attribute4 = doc.CreateAttribute("Nullable");
     attribute4.Value = att.Nullable.ToString();
     newChild.Attributes.Append(attribute4);
     XmlAttribute attribute5 = doc.CreateAttribute("InputType");
     attribute5.Value = ((int) att.InputType).ToString();
     newChild.Attributes.Append(attribute5);
     if ((att.Options != null) && (att.Options.Length > 0))
     {
         XmlNode node2 = doc.CreateElement("Options");
         foreach (string str in att.Options)
         {
             XmlNode node3 = doc.CreateElement("Item");
             node3.InnerText = str;
             node2.AppendChild(node3);
         }
         newChild.AppendChild(node2);
     }
     doc.SelectSingleNode("xml").AppendChild(newChild);
 }