Esempio n. 1
0
        private Schema CreateEnumSchema(JsonPrimitiveContract primitiveContract, Type type)
        {
            StringEnumConverter stringEnumConverter = ((JsonContract)primitiveContract).get_Converter() as StringEnumConverter ?? ((IEnumerable)this._jsonSerializerSettings.get_Converters()).OfType <StringEnumConverter>().FirstOrDefault <StringEnumConverter>();

            if (this._describeAllEnumsAsStrings || stringEnumConverter != null)
            {
                bool flag = this._describeStringEnumsInCamelCase || stringEnumConverter != null && stringEnumConverter.get_CamelCaseText();
                return(new Schema()
                {
                    type = "string",
                    @enum = flag ? (IList <object>)((IEnumerable <string>)type.GetEnumNamesForSerialization()).Select <string, string>((Func <string, string>)(name => name.ToCamelCase())).ToArray <string>() : (IList <object>)type.GetEnumNamesForSerialization()
                });
            }
            return(new Schema()
            {
                type = "integer",
                format = "int32",
                @enum = (IList <object>)type.GetEnumValues().Cast <object>().ToArray <object>()
            });
        }