Esempio n. 1
0
        public void AddProperty(string propName, object propValue, string propDesc,
                                string propCat, Type propType, bool isReadOnly, bool isExpandable)
        {
            DynamicProperty p = new DynamicProperty(propName, propValue, propDesc, propCat,
                                                    propType, isReadOnly, isExpandable);

            m_propertyCollection.Add(p);
        }
Esempio n. 2
0
        void RepopulateXmlSection(string sectionName, XmlDocument xmlDoc, PropertyDescriptorCollection props)
        {
            XmlNodeList nodes = xmlDoc.SelectNodes("configuration/categorizedSettings/" + sectionName + "/add");

            for (int i = 0; i < nodes.Count; i++)
            {
                DynamicProperty property = null;

                //Find the property in the property collection with the same name as the current node in the Xml document
                //and same category as sectionName
                foreach (PropertyDescriptor pd in props)
                {
                    if (pd.Category == sectionName && pd.Name == nodes[i].Attributes["name"].Value)
                    {
                        property = (DynamicProperty)pd;
                        break;
                    }
                }

                ////Find the property in the property collection with the same name as the current node in the Xml document
                //DynamicProperty property = (DynamicProperty)props[nodes[i].Attributes["name"].Value];

                if (property != null)
                {
                    //Set the node value to the property value which will have been set in the Property grid.
                    nodes[i].Attributes["value"].Value = property.GetValue(null).ToString();

                    //If encrypted=true, then encrypt the value before saving into configuration file.
                    if (nodes[i].Attributes["encrypted"] != null && nodes[i].Attributes["encrypted"].Value.ToLower() == "true" && !string.IsNullOrEmpty(property.GetValue(null).ToString()))
                    {
                        nodes[i].Attributes["value"].Value = property.GetValue(null).ToString().Encrypt(DefaultCryptoKey, CryptoStrength);
                    }
                    else
                    {
                        nodes[i].Attributes["value"].Value = property.GetValue(null).ToString();
                    }

                    //Check to see if we have a value for our extended custom xml attribute - the description attribute.
                    //The default description is the property name when no descripyion attribute is present.
                    //If they're not the same - then a value was passed when the property was created.
                    if (property.Description != property.Name)
                    {
                        //double check here that there is in fact a description attribute
                        if (nodes[i].Attributes["description"] != null)
                        {
                            nodes[i].Attributes["description"].Value = property.Description;
                        }
                    }
                }
            }
        }