Example #1
0
 /// <summary>
 /// Преобразование строки в enum-тип. Плевать на размер букв и Trim().
 /// Если подобрать значение не получается - ArgumentException
 /// </summary>
 /// <typeparam name="E"></typeparam>
 /// <param name="s"></param>
 /// <returns></returns>
 public static E StringToXmlEnum <E>(string s)
 {
     if (string.IsNullOrEmpty(s) || s.Trim().Length == 0)
     {
         throw new ArgumentNullException("s");
     }
     s = s.Trim().ToUpper();
     FieldInfo[] fis = typeof(E).GetFields();
     foreach (FieldInfo fi in fis)
     {
         if (fi.IsLiteral)
         {
             if (fi.Name.ToUpper() == s)
             {
                 return((E)fi.GetRawConstantValue());
             }
             object[] attrs = fi.GetCustomAttributes(false);
             foreach (object attr in attrs)
             {
                 XmlEnumAttribute xa = attr as XmlEnumAttribute;
                 if (xa != null && xa.Name.ToUpper() == s)
                 {
                     return((E)fi.GetRawConstantValue());
                 }
             }
         }
     }
     throw new ArgumentException(string.Format("Для перечисления {0} нет элемента, соответствующего значению '{1}'", typeof(E), s));
 }
Example #2
0
        /// <summary>
        /// Строится массив строковых значений указанного enum-типа.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <returns></returns>
        public static string[] GetXmlEnumList <E>()
        {
            List <string> list = new List <string>();

            FieldInfo[] fis = typeof(E).GetFields();
            foreach (FieldInfo fi in fis)
            {
                if (fi.IsLiteral)
                {
                    object[] attrs = fi.GetCustomAttributes(false);
                    if (attrs.Length == 0)
                    {
                        list.Add(fi.Name);
                    }
                    else
                    {
                        foreach (object attr in attrs)
                        {
                            XmlEnumAttribute xa = attr as XmlEnumAttribute;
                            if (xa != null)
                            {
                                list.Add(xa.Name);
                                break;
                            }
                        }
                    }
                }
            }
            return(list.ToArray());
        }
Example #3
0
        /// <summary>
        /// Функция строит Dictionary по enum-типу.
        /// Key=enum-элемент, Value=строковое значение.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <returns></returns>
        public static Dictionary <E, string> GetXmlEnumDictionary <E>()
        {
            Dictionary <E, string> dict = new Dictionary <E, string>();

            FieldInfo[] fis = typeof(E).GetFields();
            foreach (FieldInfo fi in fis)
            {
                if (fi.IsLiteral)
                {
                    E        key   = (E)fi.GetRawConstantValue();
                    object[] attrs = fi.GetCustomAttributes(false);
                    if (attrs.Length == 0)
                    {
                        dict.Add(key, fi.Name);
                    }
                    else
                    {
                        foreach (object attr in attrs)
                        {
                            XmlEnumAttribute xa = attr as XmlEnumAttribute;
                            if (xa != null)
                            {
                                dict.Add(key, xa.Name);
                                break;
                            }
                        }
                    }
                }
            }
            return(dict);
        }
        /// <remarks/>
        public static bool TryParseEnum <T>(this string text, out T result)
        {
            result = default(T);

            Type t = typeof(T);

            FieldInfo[] fields = t.GetFields();

            foreach (var field in fields)
            {
                // Check to see if the XmlEnumAttribute is defined on this field
                if (field.IsDefined(typeof(XmlEnumAttribute), false))
                {
                    object[]         o   = field.GetCustomAttributes(typeof(XmlEnumAttribute), false);
                    XmlEnumAttribute att = (XmlEnumAttribute)o[0];

                    if (att.Name == text)
                    {
                        result = (T)Enum.Parse(t, field.Name);
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
0
        private void AnalyzeEnum(Type enumType)
        {
            _enumName = enumType.Name;

            R.FieldInfo[] fieldInfos = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);

            _namedValues = new HybridDictionary(fieldInfos.Length, false);
            _valuedNames = new HybridDictionary(fieldInfos.Length, false);

            foreach (R.FieldInfo fi in fieldInfos)
            {
                if ((fi.Attributes & EnumField) == EnumField)
                {
                    string name  = fi.Name;
                    object value = fi.GetValue(null);

                    Attribute[] attrs =
                        Attribute.GetCustomAttributes(fi, typeof(XmlEnumAttribute));
                    if (attrs.Length > 0)
                    {
                        XmlEnumAttribute attr = (XmlEnumAttribute)attrs[0];
                        name = attr.Name;
                    }

                    _namedValues.Add(name, value);
                    if (!_valuedNames.Contains(value))
                    {
                        _valuedNames.Add(value, name);
                    }
                }
            }
        }
        public static string XmlEnumToString <TEnum>(this TEnum value) where TEnum : struct, IConvertible
        {
            Type enumType = typeof(TEnum);

            if (!enumType.IsEnum)
            {
                return(null);
            }

            MemberInfo member = enumType.GetMember(value.ToString()).FirstOrDefault();

            if (member == null)
            {
                return(null);
            }

            XmlEnumAttribute attribute = member.GetCustomAttributes(false).OfType <XmlEnumAttribute>().FirstOrDefault();

            if (attribute == null)
            {
                return(member.Name);
            }

            return(attribute.Name);
        }
Example #7
0
        public static T SetTypeString <T>(string NewValue) where T : struct, IConvertible
        {
            Type enumType = typeof(T);

            if (!enumType.IsEnum)
            {
                throw new Exception("The T type not is enum");
            }

            string MemberName = null;

            foreach (MemberInfo member in enumType.GetMembers())
            {
                XmlEnumAttribute attribute = member.GetCustomAttributes(false).OfType <XmlEnumAttribute>().FirstOrDefault();
                if (attribute != null)
                {
                    if (attribute.Name == NewValue)
                    {
                        MemberName = member.Name;
                        break;
                    }
                }
            }
            if (MemberName == null)
            {
                MemberName = NewValue;
            }

            return((T)Enum.Parse(typeof(T), MemberName));
        }
Example #8
0
 private static void AddXmlEnumPrint(XmlEnumAttribute att, StringBuilder printBuilder)
 {
     if (null != att)
     {
         printBuilder.Append(att.Name);
     }
     printBuilder.Append("%%");
 }
Example #9
0
        private static string GetXmlAttrUsandoElValor <T>(T valorEnum)
        {
            Type             type = valorEnum.GetType();
            FieldInfo        info = type.GetField(Enum.GetName(typeof(T), valorEnum));
            XmlEnumAttribute att  = (XmlEnumAttribute)info.GetCustomAttributes(typeof(XmlEnumAttribute), false)[0];

            return(att.Name);
        }
        public string GetXmlAttrNameFromEnumValue(CatalogoCtas.c_CodAgrup pEnumVal)
        {
            Type type = pEnumVal.GetType();

            System.Reflection.FieldInfo info = type.GetField(Enum.GetName(typeof(CatalogoCtas.c_CodAgrup), pEnumVal));
            XmlEnumAttribute            att  = (XmlEnumAttribute)info.GetCustomAttributes(typeof(XmlEnumAttribute), false)[0];

            return(att.Name);
        }
    public static int toInt(this myEnum value)
    {
        MemberInfo memberInfo = typeof(myEnum).
                                GetMember(value.ToString()).FirstOrDefault();
        XmlEnumAttribute attribute = (XmlEnumAttribute)memberInfo.
                                     GetCustomAttributes(typeof(XmlEnumAttribute), false).FirstOrDefault();

        return(int.Parse(attribute.Name));
    }
Example #12
0
        /// <summary>
        /// retorna o Enum de um tipo, passando o valor especificado em seu XmlEnumAttribute
        /// </summary>
        public static string GetXmlAttrNameFromEnumValue <T>(T pEnumVal)
        {
            Type             type = pEnumVal.GetType();
            FieldInfo        info = type.GetField(Enum.GetName(typeof(T), pEnumVal));
            XmlEnumAttribute att  = (XmlEnumAttribute)info.GetCustomAttributes(typeof(XmlEnumAttribute), false)[0];

            //If there is an xmlattribute defined, return the name

            return(att.Name);
        }
Example #13
0
        public static string GetXmlAttrNameFromEnumValue <T>(T pEnumVal)
        {
            // http://stackoverflow.com/q/3047125/194717
            Type             type = pEnumVal.GetType();
            FieldInfo        info = type.GetTypeInfo().GetField(Enum.GetName(typeof(T), pEnumVal));
            XmlEnumAttribute att  = (XmlEnumAttribute)info.GetCustomAttributes(typeof(XmlEnumAttribute), false).ToArray()[0];

            //If there is an xmlattribute defined, return the name

            return(att.Name);
        }
Example #14
0
        public LiteralAttributes(MemberInfo memberInfo, XmlAttributes xmlAtts) :
            this(memberInfo)
        {
            if (xmlAtts == null)
            {
                return;
            }

            Ignore = xmlAtts.XmlIgnore;
            if (!Ignore)
            {
                XmlChoiceIdentifier = xmlAtts.XmlChoiceIdentifier;
                XmlAttribute        = xmlAtts.XmlAttribute;
                XmlArray            = xmlAtts.XmlArray;
                XmlText             = xmlAtts.XmlText;
                XmlEnum             = xmlAtts.XmlEnum;
                DefaultValue        = (xmlAtts.XmlDefaultValue == null) ?
                                      null :
                                      new DefaultValueAttribute(xmlAtts.XmlDefaultValue);

                Xmlns = xmlAtts.Xmlns;
                if (Xmlns)
                {
                    object[] attrs = memberInfo.GetCustomAttributes(s_nsDeclType, false).ToArray();
                    XmlNamespaceDeclaration = (XmlNamespaceDeclarationsAttribute)(attrs.Length > 0 ? attrs[0] : null);
                }
                else
                {
                    XmlNamespaceDeclaration = null;
                }

                // Use if statements here so that the XmlElements collection populated by reflection
                // is eliminated only if the app developer has provided substitute XmlElementAttribute's.
                // Ditto for the XmlArrayItems and XmlAnyElements.
                if (xmlAtts.XmlElements.Count > 0)
                {
                    XmlElements = xmlAtts.XmlElements;
                }

                if (xmlAtts.XmlArrayItems.Count > 0)
                {
                    XmlArrayItems = xmlAtts.XmlArrayItems;
                }

                XmlAnyAttribute = xmlAtts.XmlAnyAttribute;

                if (xmlAtts.XmlAnyElements.Count > 0)
                {
                    XmlAnyElements = xmlAtts.XmlAnyElements;
                }
            }
        }
        public void DifferentName()
        {
            XmlEnumAttribute enum1 = new XmlEnumAttribute("enum1");
            XmlEnumAttribute enum2 = new XmlEnumAttribute("enum2");

            atts1.XmlEnum = enum1;
            atts2.XmlEnum = enum2;

            ov1.Add(typeof(SerializeMe), atts1);
            ov2.Add(typeof(SerializeMe), atts2);

            ThumbprintHelpers.DifferentThumbprint(ov1, ov2);
        }
        /// <summary>
        /// Gets the serialized name for the member.
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        public override IEnumerable <DataName> GetName(MemberInfo member)
        {
            if (member is Type)
            {
                XmlRootAttribute rootAttr = TypeCoercionUtility.GetAttribute <XmlRootAttribute>(member);
                if (rootAttr != null && !String.IsNullOrEmpty(rootAttr.ElementName))
                {
                    yield return(new DataName(rootAttr.ElementName, null, rootAttr.Namespace));
                }

                XmlTypeAttribute typeAttr = TypeCoercionUtility.GetAttribute <XmlTypeAttribute>(member);
                if (typeAttr != null && !String.IsNullOrEmpty(typeAttr.TypeName))
                {
                    yield return(new DataName(typeAttr.TypeName, null, typeAttr.Namespace));
                }

                yield break;
            }

            XmlElementAttribute elemAttr = TypeCoercionUtility.GetAttribute <XmlElementAttribute>(member);

            if (elemAttr != null && !String.IsNullOrEmpty(elemAttr.ElementName))
            {
                yield return(new DataName(elemAttr.ElementName, null, elemAttr.Namespace));
            }

            XmlAttributeAttribute attrAttr = TypeCoercionUtility.GetAttribute <XmlAttributeAttribute>(member);

            if (attrAttr != null && !String.IsNullOrEmpty(attrAttr.AttributeName))
            {
                yield return(new DataName(attrAttr.AttributeName, null, attrAttr.Namespace, true));
            }

            XmlArrayAttribute arrayAttr = TypeCoercionUtility.GetAttribute <XmlArrayAttribute>(member);

            if (arrayAttr != null && !String.IsNullOrEmpty(arrayAttr.ElementName))
            {
                // TODO: figure out a way to surface XmlArrayItemAttribute name too

                yield return(new DataName(arrayAttr.ElementName, null, arrayAttr.Namespace));
            }

            if (member is FieldInfo && ((FieldInfo)member).DeclaringType.IsEnum)
            {
                XmlEnumAttribute enumAttr = TypeCoercionUtility.GetAttribute <XmlEnumAttribute>(member);
                if (enumAttr != null && !String.IsNullOrEmpty(enumAttr.Name))
                {
                    yield return(new DataName(enumAttr.Name));
                }
            }
        }
Example #17
0
        /// <summary>
        /// Преобразование enum-элемента в строку. Если для этого элемента определен атрибут XmlEnumAttribute,
        /// то берется значение из этого атрибута. Если такого атрибута нет, то берется значение.ToString()
        /// </summary>
        /// <typeparam name="E">enumeration</typeparam>
        /// <param name="item">enum item</param>
        /// <returns></returns>
        public static string GetXmlEnumString <E>(E item)
        {
            FieldInfo fi = typeof(E).GetField(item.ToString());

            if (fi != null)
            {
                object[] attrs = fi.GetCustomAttributes(false);
                foreach (object attr in attrs)
                {
                    XmlEnumAttribute xa = attr as XmlEnumAttribute;
                    if (xa != null)
                    {
                        return(xa.Name);
                    }
                }
            }
            return(item.ToString());
        }
Example #18
0
        static XmlEnumParser()
        {
            Type type = typeof(TReturn);

            MemberInfo[] members = type.GetMembers(BindingFlags.Public | BindingFlags.Static);
            string[]     names   = Enum.GetNames(type);
            values = new Dictionary <string, TReturn>();
            Array array = type.GetEnumValues();

            foreach (var member in members)
            {
                object[] cas = member.GetCustomAttributes(typeof(XmlEnumAttribute), false);
                if (cas.Length > 0)
                {
                    XmlEnumAttribute attribute = (XmlEnumAttribute)cas[0];
                    values.Add(attribute.Name, (TReturn)Enum.Parse(type, member.Name));
                }
            }
        }
Example #19
0
        /// <summary>
        /// Returns the XmlEnum value for an enum value
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static T FromXmlString <T>(string val)
        {
            Type type = typeof(T);

            MemberInfo[] memInfo = type.GetMembers();

            foreach (MemberInfo info in memInfo)
            {
                foreach (object attribute in info.GetCustomAttributes())
                {
                    XmlEnumAttribute xmlEnum = attribute as XmlEnumAttribute;

                    if (xmlEnum != null && xmlEnum.Name == val)
                    {
                        return((T)Enum.Parse(type, info.Name));
                    }
                }
            }
            return(default(T));
        }
Example #20
0
        public static XmlAttributeOverrides GetEnumClassFilter(List <Type> typeList)
        {
            var overrides = new XmlAttributeOverrides();

            foreach (var type in typeList)
            {
                string[] names  = System.Enum.GetNames(type);
                var      values = System.Enum.GetValues(type);
                for (int i = 0; i < names.Length; i++)
                {
                    var attrs   = new XmlAttributes();
                    var xmlEnum = new XmlEnumAttribute();
                    xmlEnum.Name  = ((int)values.GetValue(i)).ToString(CultureName);
                    attrs.XmlEnum = xmlEnum;
                    overrides.Add(type, names[i], attrs);
                }
            }

            return(overrides);
        }
Example #21
0
        /// <summary>
        /// Returns the XmlEnum value for an enum value
        /// </summary>
        /// <param name="enumVal"></param>
        /// <returns></returns>
        public static string ToXmlString(Enum enumVal)
        {
            Type type = enumVal.GetType();

            MemberInfo[] memInfo = type.GetMember(enumVal.ToString());

            foreach (MemberInfo info in memInfo)
            {
                foreach (object attribute in info.GetCustomAttributes())
                {
                    XmlEnumAttribute xmlEnum = attribute as XmlEnumAttribute;

                    if (xmlEnum != null)
                    {
                        return(xmlEnum.Name);
                    }
                }
            }
            return(null);
        }
        public static string ConvertToString(Enum e)
        {
            // Get the Type of the enum
            Type t = e.GetType();

            // Get the FieldInfo for the member field with the enums name
            FieldInfo info = t.GetField(e.ToString("G"));

            // Check to see if the XmlEnumAttribute is defined on this field
            if (!info.IsDefined(typeof(XmlEnumAttribute), false))
            {
                // If no XmlEnumAttribute then return the string version of the enum.
                return(e.ToString("G"));
            }

            // Get the XmlEnumAttribute
            object[]         o   = info.GetCustomAttributes(typeof(XmlEnumAttribute), false);
            XmlEnumAttribute att = (XmlEnumAttribute)o[0];

            return(att.Name);
        }
Example #23
0
        public void TestEnumDataElementsGeneration()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml");

            DataContractEnum rootElement = CreateDefaultDataContractEnum();

            rootElement.EnumNamedValues.AddRange(LoadEnumDataElements());
            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);

            TypeAsserter.AssertExistPublicField(EnumElement1Name, generatedType);

            XmlEnumAttribute attrib = TypeAsserter.AssertAttribute <XmlEnumAttribute>(generatedType.GetField(EnumElement1Name));

            Assert.AreEqual <string>(EnumElement1Value, attrib.Name);

            TypeAsserter.AssertExistPublicField(EnumElement2Name, generatedType);
            attrib = TypeAsserter.AssertAttribute <XmlEnumAttribute>(generatedType.GetField(EnumElement2Name));
            Assert.AreEqual <string>(EnumElement2Value, attrib.Name);
        }
Example #24
0
        public static string GetXmlEnumString(object item)
        {
            if (item == null || !item.GetType().IsEnum)
            {
                return("");
            }
            FieldInfo fi = item.GetType().GetField(item.ToString());

            if (fi != null)
            {
                object[] attrs = fi.GetCustomAttributes(false);
                foreach (object attr in attrs)
                {
                    XmlEnumAttribute xa = attr as XmlEnumAttribute;
                    if (xa != null)
                    {
                        return(xa.Name);
                    }
                }
            }
            return(item.ToString());
        }
    // Return an XmlSerializer used for overriding.
    public XmlSerializer CreateOverrider()
    {
        // Create the XmlOverrides and XmlAttributes objects.
        XmlAttributeOverrides xOver  = new XmlAttributeOverrides();
        XmlAttributes         xAttrs = new XmlAttributes();

        // Add an XmlEnumAttribute for the FoodType.Low enumeration.
        XmlEnumAttribute xEnum = new XmlEnumAttribute();

        xEnum.Name     = "Cold";
        xAttrs.XmlEnum = xEnum;
        xOver.Add(typeof(FoodType), "Low", xAttrs);

        // Add an XmlEnumAttribute for the FoodType.High enumeration.
        xAttrs         = new XmlAttributes();
        xEnum          = new XmlEnumAttribute();
        xEnum.Name     = "Hot";
        xAttrs.XmlEnum = xEnum;
        xOver.Add(typeof(FoodType), "High", xAttrs);

        // Create the XmlSerializer, and return it.
        return(new XmlSerializer(typeof(Food), xOver));
    }
        /// <remarks/>
        public static T ParseEnum <T>(this string text)
        {
            Type t = typeof(T);

            FieldInfo[] fields = t.GetFields();

            foreach (var field in fields)
            {
                // Check to see if the XmlEnumAttribute is defined on this field
                if (field.IsDefined(typeof(XmlEnumAttribute), false))
                {
                    object[]         o   = field.GetCustomAttributes(typeof(XmlEnumAttribute), false);
                    XmlEnumAttribute att = (XmlEnumAttribute)o[0];

                    if (att.Name == text)
                    {
                        return((T)Enum.Parse(t, field.Name));
                    }
                }
            }

            //  return default value if not found
            return((T)Enum.Parse(t, Enum.GetNames(t)[0]));
        }
Example #27
0
 protected override string GetDisplayName(XmlEnumAttribute attribute)
 {
     return(attribute.Name);
 }
Example #28
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlAttributes(ICustomAttributeProvider provider)
        {
            object[] attrs = provider.GetCustomAttributes(false);

            // most generic <any/> matches everything
            XmlAnyElementAttribute wildcard = null;

            for (int i = 0; i < attrs.Length; i++)
            {
                if (attrs[i] is XmlIgnoreAttribute || attrs[i] is ObsoleteAttribute || attrs[i].GetType() == IgnoreAttribute)
                {
                    _xmlIgnore = true;
                    break;
                }
                else if (attrs[i] is XmlElementAttribute)
                {
                    _xmlElements.Add((XmlElementAttribute)attrs[i]);
                }
                else if (attrs[i] is XmlArrayItemAttribute)
                {
                    _xmlArrayItems.Add((XmlArrayItemAttribute)attrs[i]);
                }
                else if (attrs[i] is XmlAnyElementAttribute)
                {
                    XmlAnyElementAttribute any = (XmlAnyElementAttribute)attrs[i];
                    if ((any.Name == null || any.Name.Length == 0) && any.NamespaceSpecified && any.Namespace == null)
                    {
                        // ignore duplicate wildcards
                        wildcard = any;
                    }
                    else
                    {
                        _xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]);
                    }
                }
                else if (attrs[i] is DefaultValueAttribute)
                {
                    _xmlDefaultValue = ((DefaultValueAttribute)attrs[i]).Value;
                }
                else if (attrs[i] is XmlAttributeAttribute)
                {
                    _xmlAttribute = (XmlAttributeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlArrayAttribute)
                {
                    _xmlArray = (XmlArrayAttribute)attrs[i];
                }
                else if (attrs[i] is XmlTextAttribute)
                {
                    _xmlText = (XmlTextAttribute)attrs[i];
                }
                else if (attrs[i] is XmlEnumAttribute)
                {
                    _xmlEnum = (XmlEnumAttribute)attrs[i];
                }
                else if (attrs[i] is XmlRootAttribute)
                {
                    _xmlRoot = (XmlRootAttribute)attrs[i];
                }
                else if (attrs[i] is XmlTypeAttribute)
                {
                    _xmlType = (XmlTypeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlAnyAttributeAttribute)
                {
                    _xmlAnyAttribute = (XmlAnyAttributeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlChoiceIdentifierAttribute)
                {
                    _xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attrs[i];
                }
                else if (attrs[i] is XmlNamespaceDeclarationsAttribute)
                {
                    _xmlns = true;
                }
            }
            if (_xmlIgnore)
            {
                _xmlElements.Clear();
                _xmlArrayItems.Clear();
                _xmlAnyElements.Clear();
                _xmlDefaultValue     = null;
                _xmlAttribute        = null;
                _xmlArray            = null;
                _xmlText             = null;
                _xmlEnum             = null;
                _xmlType             = null;
                _xmlAnyAttribute     = null;
                _xmlChoiceIdentifier = null;
                _xmlns = false;
            }
            else
            {
                if (wildcard != null)
                {
                    _xmlAnyElements.Add(wildcard);
                }
            }
        }
        /// <summary>
        /// Creates the dependency XML serializer.
        /// </summary>
        /// <returns>Initialized XML serializer</returns>
        private static XmlSerializer CreateDependencyXmlSerializer()
        {
            // Handle enums
            var xAttrOver           = new XmlAttributeOverrides();
            var xAttrs              = new XmlAttributes();
            var xDependencyTypeEnum = new XmlEnumAttribute {
                Name = "Source"
            };

            xAttrs.XmlEnum = xDependencyTypeEnum;
            xAttrOver.Add(typeof(DependencyType), "Source", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyTypeEnum = new XmlEnumAttribute {
                Name = "Binary"
            };
            xAttrs.XmlEnum = xDependencyTypeEnum;
            xAttrOver.Add(typeof(DependencyType), "Binary", xAttrs);
            xAttrs = new XmlAttributes();
            var xDependencyProviderSettingsTypeEnum = new XmlEnumAttribute {
                Name = "SourceControlSettings"
            };

            xAttrs.XmlEnum = xDependencyProviderSettingsTypeEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "SourceControlSettings", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderSettingsTypeEnum = new XmlEnumAttribute {
                Name = "SourceControlCopySettings"
            };
            xAttrs.XmlEnum = xDependencyProviderSettingsTypeEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "SourceControlCopySettings", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderSettingsTypeEnum = new XmlEnumAttribute {
                Name = "BuildResultSettings"
            };
            xAttrs.XmlEnum = xDependencyProviderSettingsTypeEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BuildResultSettings", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderSettingsTypeEnum = new XmlEnumAttribute {
                Name = "FileShareSettings"
            };
            xAttrs.XmlEnum = xDependencyProviderSettingsTypeEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "FileShareSettings", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderSettingsTypeEnum = new XmlEnumAttribute {
                Name = "BinaryRepositorySettings"
            };
            xAttrs.XmlEnum = xDependencyProviderSettingsTypeEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BinaryRepositorySettings", xAttrs);
            xAttrs = new XmlAttributes();
            var xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "ServerRootPath"
            };

            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "ServerRootPath", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "IncludeFilter"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "IncludeFilter", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "ExcludedFiles"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "ExcludedFiles", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "IncludeFoldersFilter"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "IncludeFoldersFilter", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "ExcludeFoldersFilter"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "ExcludeFoldersFilter", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "FileShareRootPath"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "FileShareRootPath", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "ComponentName"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "ComponentName", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "VersionNumber"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "VersionNumber", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "VersionSpec"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "VersionSpec", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "TeamProjectName"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "TeamProjectName", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BuildDefinition"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BuildDefinition", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BuildNumber"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BuildNumber", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BuildQuality"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BuildQuality", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BuildStatus"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BuildStatus", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BinaryTeamProjectCollectionUrl"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BinaryTeamProjectCollectionUrl", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "BinaryRepositoryTeamProject"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "BinaryRepositoryTeamProject", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "RelativeOutputPath"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "RelativeOutputPath", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "FolderMappings"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "FolderMappings", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "CompressedDependency"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "CompressedDependency", xAttrs);
            xAttrs = new XmlAttributes();
            xDependencyProviderValidSettingNameEnum = new XmlEnumAttribute {
                Name = "IgnoreInSideBySideAnomalyChecks"
            };
            xAttrs.XmlEnum = xDependencyProviderValidSettingNameEnum;
            xAttrOver.Add(typeof(DependencyProviderSettingsType), "IgnoreInSideBySideAnomalyChecks", xAttrs);

            var serializer = new XmlSerializer(typeof(XmlComponent), xAttrOver);

            serializer.UnknownNode      += SerializerUnknownNode;
            serializer.UnknownAttribute += SerializerUnknownAttribute;

            return(serializer);
        }
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write(this.ToStringHelper.ToStringWithCulture(SchemaSetClassCreator.GetLicenseText()));
            this.Write("\r\n");

            SchemaSetClassCreator generator = new SchemaSetClassCreator(mlPath, mlVersion, enumClassNames, versionString);

            this.Write(@"//This code was generated using the Energistics Generator tool.  Direct changes to this code will be lost
//during regeneration.

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;

using Energistics.DataAccess.");
            this.Write(this.ToStringHelper.ToStringWithCulture(mlVersion));
            this.Write(".ComponentSchemas;\r\nusing Energistics.DataAccess.");
            this.Write(this.ToStringHelper.ToStringWithCulture(mlVersion));
            this.Write(".ReferenceData;\r\nusing Energistics.DataAccess.Reflection;\r\nusing Energistics.Data" +
                       "Access.Validation;\r\n\r\nnamespace Energistics.DataAccess.");
            this.Write(this.ToStringHelper.ToStringWithCulture(mlVersion));
            this.Write("\r\n{\r\n    #region Classes\r\n");

            foreach (Type type in generator.Classes)
            {
                if (generator.IsComponentSchemaType(type))
                {
                    this.Write("    namespace ComponentSchemas \r\n    {\r\n");
                }

                this.Write("    /// <summary>\r\n    /// ");
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type)));
                this.Write("\r\n    /// </summary>\r\n");

                foreach (XmlIncludeAttribute include in type.GetCustomAttributes(typeof(XmlIncludeAttribute), false))
                {
                    this.Write("    [System.Xml.Serialization.XmlIncludeAttribute(typeof(");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.RenameClass(include.Type)));
                    this.Write("))]\r\n");
                }

                this.Write("    [System.CodeDom.Compiler.GeneratedCodeAttribute(\"");
                this.Write(this.ToStringHelper.ToStringWithCulture(Assembly.GetExecutingAssembly().GetName().Name));
                this.Write("\", \"");
                this.Write(this.ToStringHelper.ToStringWithCulture(Assembly.GetExecutingAssembly().GetName().Version));
                this.Write("\")]\r\n    [System.SerializableAttribute()]\r\n    [System.Diagnostics.DebuggerStepTh" +
                           "roughAttribute()]\r\n    [System.ComponentModel.DesignerCategoryAttribute(\"code\")]" +
                           "\r\n");

                if (generator.GetXmlRootName(type) != null)
                {
                    this.Write("    [System.Xml.Serialization.XmlTypeAttribute(Namespace=\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlNamespace(type)));
                    this.Write("\")]\r\n    [System.Xml.Serialization.XmlRootAttribute(\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlRootName(type)));
                    this.Write("\", Namespace=\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlNamespace(type)));
                    this.Write("\", IsNullable=false)]\r\n");
                }
                else
                {
                    this.Write("    [System.Xml.Serialization.XmlTypeAttribute(TypeName=\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(type.Name));
                    this.Write("\", Namespace=\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlNamespace(type)));
                    this.Write("\")]\r\n");
                }

                this.Write("\t");
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetEnergisticsDataObjectAttribute(type)));
                this.Write("[Description(\"");
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type).Replace("\"", "")));
                this.Write("\")]\r\n    public");
                this.Write(this.ToStringHelper.ToStringWithCulture(type.IsAbstract ? " abstract" : string.Empty));
                this.Write(" partial class ");
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.RenameClass(type, true)));
                this.Write(" ");
                this.Write(this.ToStringHelper.ToStringWithCulture(type.BaseType.Equals(typeof(object)) ?  ": Object" : string.Format(": {0}", generator.RenameClass(type.BaseType))));
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.IsEnergisticsCollection(type) ? ", IEnergisticsCollection" : generator.GetDataObjectInterface(type)));
                this.Write(", INotifyPropertyChanged\r\n    {\r\n");
                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetConstructor(type)));
                this.Write("\r\n");

                foreach (var property in type.GetProperties())
                {
                    if (property.DeclaringType.Equals(type))
                    {
                        if (property.GetCustomAttributes(typeof(XmlIgnoreAttribute), false).Length > 0)
                        {
                            this.Write("        ");
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                            this.Write("\r\n        [XmlIgnore]\r\n        [Browsable(false)]\r\n");
                        }
                        else
                        if (property.GetCustomAttributes(typeof(XmlTextAttribute), false).Length > 0)
                        {
                            this.Write("        ");
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                            this.Write("\r\n        ");
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetValidationAttributes(type, property)));
                            this.Write("\r\n        [XmlText]\r\n");
                        }
                        else if (property.GetCustomAttributes(typeof(XmlElementAttribute), false).Length > 1)
                        {
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.ExpandChoiceAttributes(type, property)));
                            this.Write("\r\n");

                            continue;
                        }
                        else
                        {
                            object[] elementAttribute = property.GetCustomAttributes(typeof(XmlElementAttribute), false);
                            if (elementAttribute.Length > 0)
                            {
                                XmlElementAttribute xmlElemAttr = (elementAttribute[0] as XmlElementAttribute);

                                this.Write("        ");
                                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                                this.Write("\r\n\t\t");
                                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetValidationAttributes(type, property)));
                                this.Write("\r\n\t\t");
                                this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlElementAttrTag(xmlElemAttr, property)));
                                this.Write("\r\n");
                            }
                            else
                            {
                                object[] attributetAttributes = property.GetCustomAttributes(typeof(XmlAttributeAttribute), false);
                                if (attributetAttributes.Length > 0)
                                {
                                    XmlAttributeAttribute attribute = attributetAttributes[0] as XmlAttributeAttribute;

                                    this.Write("\t\t");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                                    this.Write("\r\n\t\t");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetValidationAttributes(type, property)));
                                    this.Write("\r\n        [XmlAttribute(\"");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(string.IsNullOrEmpty(attribute.AttributeName) ? property.Name : attribute.AttributeName));
                                    this.Write("\"");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(attribute.Form.HasFlag(XmlSchemaForm.Qualified) ? ", Form = System.Xml.Schema.XmlSchemaForm.Qualified" : String.Empty));
                                    this.Write(this.ToStringHelper.ToStringWithCulture(string.IsNullOrEmpty(attribute.Namespace) ? String.Empty : String.Format(", Namespace = \"{0}\"", attribute.Namespace)));
                                    this.Write(")]\r\n\t\t");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetSurrogate(type, property)));
                                    this.Write("\r\n");
                                }
                                else
                                {
                                    this.Write("        ");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                                    this.Write("\r\n\t\t");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetValidationAttributes(type, property)));
                                    this.Write("\r\n\t\t");
                                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlElementOrXmlArray(type, property)));
                                    this.Write("\r\n");
                                }
                            }
                        }



                        this.Write("        public ");
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetPropertyType(property)));
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.MakePropertyNullable(property)));
                        this.Write(" ");
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.RenameProperty(property)));
                        this.Write(" ");
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetGetterSetter(null, type, property)));
                        this.Write("\r\n");

                        if (generator.IsItemsList(type, property))
                        {
                            this.Write("        ");
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, property.Name)));
                            this.Write("\r\n        [XmlIgnore]\t\t\r\n        public IList Items\r\n        {\r\n\t\t    get\r\n\t\t\t{\r\n" +
                                       "\t\t\t    return ");
                            this.Write(this.ToStringHelper.ToStringWithCulture(generator.RenameProperty(property)));
                            this.Write(";\r\n\t\t\t}\r\n        }\r\n");
                        }
                    }
                }

                if (type.GetProperty("commonData") != null && type.GetProperty("customData") != null)
                {
                    this.Write(@"        
        #region ICommonDataObject Members

        ICommonData ICommonDataObject.CommonData
        {
            get { return CommonData; }
            set { CommonData = value as CommonData; }
        }

        ICustomData ICommonDataObject.CustomData
        {
            get { return CustomData; }
            set { CustomData = value as CustomData; }
        }

        #endregion
");
                }

                this.Write("\r\n");

                if (type.BaseType == typeof(Object))
                {
                    this.Write(@"        
		#region INotifyPropertyChanged Members
		/// <summary>
        /// Occurs when a property value changes. 
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

		/// <summary>
        /// Triggers PropertyChanged Event
        /// </summary>
        /// <param name=""info"">Name of property changed</param>
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion INotifyPropertyChanged Members
");
                }

                this.Write("    } //here\r\n");

                if (generator.IsComponentSchemaType(type))
                {
                    this.Write("    }\r\n");
                }

                this.Write("\r\n");
            }

            this.Write("    #endregion\r\n\r\n    #region Enumerations\r\n    namespace ReferenceData {\r\n");

            foreach (Type type in generator.Enums)
            {
                if (!enumClassNames.Contains(type.Name))
                {
                    this.Write("        /// <summary>\r\n        /// ");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type)));
                    this.Write("\r\n        /// </summary>\r\n        [System.CodeDom.Compiler.GeneratedCodeAttribute" +
                               "(\"xsd\", \"4.0.30319.1\")]\r\n        [System.SerializableAttribute()]\r\n        [Syst" +
                               "em.Xml.Serialization.XmlTypeAttribute(Namespace=\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetXmlNamespace(type)));
                    this.Write("\")]\r\n        [Description(\"");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type).Replace("\"", "")));
                    this.Write("\")]\r\n        public enum ");
                    this.Write(this.ToStringHelper.ToStringWithCulture(generator.RenameClass(type, true)));
                    this.Write(" \r\n        {\r\n");

                    FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public);

                    for (int i = 0; i < fields.Length; i++)
                    {
                        FieldInfo field          = fields[i];
                        object[]  enumAttributes = field.GetCustomAttributes(typeof(XmlEnumAttribute), false);

                        this.Write("        ");
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetDescription(type, field.Name)));
                        this.Write("\r\n");

                        if (enumAttributes.Length > 0)
                        {
                            XmlEnumAttribute attribute = enumAttributes[0] as XmlEnumAttribute;

                            this.Write("          [XmlEnum(\"");
                            this.Write(this.ToStringHelper.ToStringWithCulture(string.IsNullOrEmpty(field.Name) ? field.Name : attribute.Name));
                            this.Write("\")]\r\n");
                        }

                        this.Write("          ");
                        this.Write(this.ToStringHelper.ToStringWithCulture(generator.GetEnumName(field.Name)));
                        this.Write(this.ToStringHelper.ToStringWithCulture(i == fields.Length - 1 ? string.Empty : ","));
                        this.Write("\r\n");
                    }

                    this.Write("        }\r\n");
                } // end if
            }     // end for

            this.Write("    }\r\n    #endregion\r\n}");
            return(this.GenerationEnvironment.ToString());
        }