Microsoft.Web.Administration.ConfigurationAttributeSchema.GetEnumValues C# (CSharp) Метод

GetEnumValues() публичный Метод

public GetEnumValues ( ) : ConfigurationEnumValueCollection
Результат ConfigurationEnumValueCollection
        public ConfigurationEnumValueCollection GetEnumValues()
        {
            return _collection ?? (_collection = new ConfigurationEnumValueCollection());
        }

Usage Example

Пример #1
0
        public static string Format(this ConfigurationAttributeSchema schema, object value)
        {
            if (value == null)
            {
                return(null);
            }

            if (schema.Type == "enum")
            {
                return(schema.GetEnumValues().GetName((long)value));
            }

            if (schema.Type == "flags")
            {
                var longValue = (long)value;
                var result    = new StringBuilder();
                foreach (ConfigurationEnumValue item in schema.GetEnumValues())
                {
                    if (item.Value == 0)
                    {
                        if (longValue == 0)
                        {
                            return(item.Name);
                        }

                        continue;
                    }

                    if ((longValue & item.Value) == item.Value)
                    {
                        result.AppendFormat("{0},", item.Name);
                    }
                }

                if (result[result.Length - 1] == ',')
                {
                    result.Length--;
                }

                return(result.ToString());
            }

            if (schema.Type == "bool")
            {
                return((bool)value ? "true" : "false");
            }

            return(value.ToString());
        }