private static StringSetCollection BuildApprovedFunctionsStringSet()
        {
            var result = new StringSetCollection();

            result.Add("_TlgWrite");
            return(result);
        }
 private static StringSetCollection BuildApprovedFunctionsStringSet()
 {
     var result = new StringSetCollection();
     result.Add("_TlgWrite");
     return result;
 }
        private static void SaveStringSet(XmlWriter writer, StringSetCollection items, string key)
        {
            writer.WriteStartElement(PROPERTY_ID);
            writer.WriteAttributeString(KEY_ID, key);
            writer.WriteAttributeString(TYPE_ID, "StringSet");

            string[] sorted = new string[items.Count];
            items.CopyTo(sorted, 0);
            Array.Sort(sorted);

            foreach (string item in sorted)
            {
                writer.WriteStartElement(ITEM_ID);
                writer.WriteString(item);
                writer.WriteEndElement(); // Item
            }

            writer.WriteEndElement(); // Property
        }
        public static void LoadPropertiesFromXmlStream(this IDictionary propertyBag, XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (propertyBag == null)
            {
                throw new ArgumentNullException(nameof(propertyBag));
            }

            while (reader.IsStartElement(PROPERTIES_ID) || reader.IsStartElement(PROPERTY_ID))
            {
                string key = null;
                string value = null;
                bool isEmpty;

                if (reader.IsStartElement(PROPERTIES_ID))
                {
                    key = reader.GetAttribute(KEY_ID);

                    string typeName = reader.GetAttribute(TYPE_ID);

                    IDictionary nestedPropertyBag;

                    if (String.IsNullOrEmpty(typeName))
                    {
                        nestedPropertyBag = new PropertiesDictionary();
                    }
                    else
                    {
                        Type type = GetPropertiesDictionaryType(typeName);
                        nestedPropertyBag = (IDictionary)Activator.CreateInstance(type);
                    }

                    propertyBag[key] = nestedPropertyBag;
                    isEmpty = reader.IsEmptyElement;
                    reader.ReadStartElement(PROPERTIES_ID);
                    LoadPropertiesFromXmlStream(nestedPropertyBag, reader);
                    if (!isEmpty) { reader.ReadEndElement(); }
                }
                else
                {
                    key = reader.GetAttribute(KEY_ID);
                    value = reader.GetAttribute(VALUE_ID);
                    string typeName = reader.GetAttribute(TYPE_ID);
                    isEmpty = reader.IsEmptyElement;

                    if (typeName == STRING_SET_ID)
                    {
                        StringSetCollection set = new StringSetCollection();
                        propertyBag[key] = set;
                        LoadStringSet(set, reader);
                        if (!isEmpty) { reader.ReadEndElement(); }
                        continue;
                    }

                    reader.ReadStartElement(PROPERTY_ID);
                    Type propertyType = GetPropertiesDictionaryType(typeName);

                    if (typeName == "System.Version")
                    {
                        Version version;
                        bool succeeded = Version.TryParse(value, out version);
                        Debug.Assert(succeeded);
                        propertyBag[key] = version;
                        continue;
                    }

                    TypeConverter tc = TypeDescriptor.GetConverter(propertyType);
                    Debug.Assert(tc.CanConvertFrom(typeof(string)));

                    object propertyValue = tc.ConvertFromString(value);
                    propertyBag[key] = propertyValue;

                    Debug.Assert(isEmpty);
                }
            }
        }
        private static void LoadStringSet(StringSetCollection set, XmlReader reader)
        {
            reader.ReadStartElement(PROPERTY_ID);

            while (reader.IsStartElement(ITEM_ID))
            {
                string item;
                bool isEmptyItem;

                isEmptyItem = reader.IsEmptyElement;
                reader.ReadStartElement();
                item = reader.ReadString();
                set.Add(item);
                if (!isEmptyItem) reader.ReadEndElement();
            }
        }