Microsoft.Web.Administration.ConfigurationAttributeSchemaExtensions.Format C# (CSharp) Method

Format() public static method

public static Format ( this schema, object value ) : string
schema this
value object
return string
        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();
        }
    }
ConfigurationAttributeSchemaExtensions