Beispiel #1
0
        private static bool ParseEnum(XDocument doc)
        {
            IEnumerable <XElement> xEnum = (from x in doc.Descendants()
                                            where x.Name.LocalName == "EnumType"
                                            select x).ToList();

            if (!xEnum.Any())
            {
                Log.Log.Write("ParseDocunent.ParseEnum: EnumTypeEnumType == null", "Warning ");
                return(false);
            }

            foreach (var Enum in xEnum)
            {
                if (Enum.Attribute("id") == null)
                {
                    Log.Log.Write("ParseDocunent.ParseEnum: EnumTypeEnumType.id == null", "Warning ");
                    continue;
                }

                var nameEnum = Enum.Attribute("id")?.Value;

                ServerModel.ListEnumType.Add(new ServerModel.EnumType(nameEnum));

                IEnumerable <XElement> xEnumVal = (from x in Enum.Descendants()
                                                   where x.Name.LocalName == "EnumVal"
                                                   select x).ToList();

                if (!xEnumVal.Any())
                {
                    Log.Log.Write("ParseDocunent.ParseEnum: EnumVal == null", "Warning ");
                    return(false);
                }

                foreach (var enumVal in xEnumVal)
                {
                    var nameEnumVal = Convert.ToInt32(enumVal.Attribute("ord")?.Value);
                    var valEnumVal  = enumVal.Value;

                    ServerModel.ListEnumType.Last().ListEnumVal.Add(new ServerModel.EnumType.EnumVal(nameEnumVal, valEnumVal));
                }
            }

            return(true);
        }
Beispiel #2
0
 /// <summary>
 /// Gets the first <see href="Attribute"/> of type <typeparamref name="T"/> associated with the
 /// enumeration value given in the <paramref name="provider"/> parameter.
 /// </summary>
 /// <typeparam name="T">The attribute type to search for.</typeparam>
 /// <param name="provider">An enumeration value on which to search for the attribute.</param>
 /// <returns>The first attribute found on the source.</returns>
 public static T Attribute <T>(this Enum provider) where T : Attribute
 {
     return(provider.Attribute(typeof(T)) as T);
 }
Beispiel #3
0
        public static string DisplayName(this Enum value)
        {
            var attribute = value.Attribute <DisplayAttribute>();

            return(attribute != null ? attribute.Name : value.ToString());
        }
Beispiel #4
0
 public static String Humanize(this Enum source)
 {
     return(source.Attribute <DescriptionAttribute>().Description);
 }