コード例 #1
0
        public JsonDictionaryContract(Type underlyingType) : base(underlyingType)
        {
            Type type;
            Type type2;

            base.enum15_0 = Enum15.Dictionary;
            if (Class194.smethod_14(underlyingType, typeof(IDictionary <,>), out this.type_3))
            {
                type  = this.type_3.GetGenericArguments()[0];
                type2 = this.type_3.GetGenericArguments()[1];
                if (Class194.smethod_12(base.UnderlyingType, typeof(IDictionary <,>)))
                {
                    base.CreatedType = typeof(Dictionary <,>).MakeGenericType(new Type[] { type, type2 });
                }
            }
            else
            {
                Class194.smethod_19(base.UnderlyingType, out type, out type2);
                if (base.UnderlyingType == typeof(IDictionary))
                {
                    base.CreatedType = typeof(Dictionary <object, object>);
                }
            }
            if ((type != null) && (type2 != null))
            {
                this.ConstructorInfo_0 = Class191.smethod_3(base.CreatedType, typeof(KeyValuePair <,>).MakeGenericType(new Type[] { type, type2 }));
            }
            this.Boolean_0           = !typeof(IDictionary).IsAssignableFrom(base.CreatedType);
            this.DictionaryKeyType   = type;
            this.DictionaryValueType = type2;
            if (this.DictionaryValueType != null)
            {
                this.bool_7 = Class194.smethod_10(this.DictionaryValueType);
            }
        }
コード例 #2
0
        private JsonSchema method_5(Type type_0, Required required_0, bool bool_0)
        {
            JsonConverter converter;
            Class134      class4 = new Class134 {
                type_0 = type_0
            };

            Class203.smethod_2(class4.type_0, "type");
            string str  = this.method_4(class4.type_0, false);
            string str2 = this.method_4(class4.type_0, true);

            if (!string.IsNullOrEmpty(str))
            {
                JsonSchema schema = this.jsonSchemaResolver_0.GetSchema(str);
                if (schema != null)
                {
                    if ((required_0 != Required.Always) && !smethod_0(schema.Type, JsonSchemaType.Null))
                    {
                        schema.Type = ((JsonSchemaType)schema.Type) | JsonSchemaType.Null;
                    }
                    if (bool_0 && (schema.Required != true))
                    {
                        schema.Required = true;
                    }
                    return(schema);
                }
            }
            if (this.ilist_0.Any <Class133>(new Func <Class133, bool>(class4.method_0)))
            {
                throw new JsonException("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".smethod_0(CultureInfo.InvariantCulture, class4.type_0));
            }
            JsonContract contract = this.ContractResolver.ResolveContract(class4.type_0);

            if (((converter = contract.Converter) != null) || ((converter = contract.JsonConverter_0) != null))
            {
                JsonSchema schema2 = converter.GetSchema();
                if (schema2 != null)
                {
                    return(schema2);
                }
            }
            this.method_0(new Class133(class4.type_0, new JsonSchema()));
            if (str2 != null)
            {
                this.JsonSchema_0.Id = str2;
            }
            if (bool_0)
            {
                this.JsonSchema_0.Required = true;
            }
            this.JsonSchema_0.Title       = this.method_2(class4.type_0);
            this.JsonSchema_0.Description = this.method_3(class4.type_0);
            if (converter != null)
            {
                this.JsonSchema_0.Type = 0x7f;
            }
            else
            {
                switch (contract.enum15_0)
                {
                case Enum15.Object:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                    this.method_8(class4.type_0, (JsonObjectContract)contract);
                    goto Label_04CD;

                case Enum15.Array:
                    {
                        this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Array, required_0));
                        this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                        JsonArrayAttribute attribute = Class139.smethod_0(class4.type_0) as JsonArrayAttribute;
                        bool flag = (attribute == null) || attribute.AllowNullItems;
                        Type type = Class194.smethod_18(class4.type_0);
                        if (type != null)
                        {
                            this.JsonSchema_0.Items = new List <JsonSchema>();
                            this.JsonSchema_0.Items.Add(this.method_5(type, !flag ? Required.Always : Required.Default, false));
                        }
                        goto Label_04CD;
                    }

                case Enum15.Primitive:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_10(class4.type_0, required_0));
                    if (((((JsonSchemaType)this.JsonSchema_0.Type) == JsonSchemaType.Integer) && class4.type_0.smethod_7()) && !class4.type_0.IsDefined(typeof(FlagsAttribute), true))
                    {
                        this.JsonSchema_0.Enum = new List <JToken>();
                        foreach (Class187 <long> class3 in Class186.smethod_2 <long>(class4.type_0))
                        {
                            JToken item = JToken.FromObject(class3.Prop_0);
                            this.JsonSchema_0.Enum.Add(item);
                        }
                    }
                    goto Label_04CD;

                case Enum15.String:
                    {
                        JsonSchemaType type2 = !Class194.smethod_9(contract.UnderlyingType) ? JsonSchemaType.String : this.method_6(JsonSchemaType.String, required_0);
                        this.JsonSchema_0.Type = new JsonSchemaType?(type2);
                        goto Label_04CD;
                    }

                case Enum15.Dictionary:
                    Type type3;
                    Type type4;
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    Class194.smethod_19(class4.type_0, out type3, out type4);
                    if ((type3 != null) && (this.ContractResolver.ResolveContract(type3).enum15_0 == Enum15.Primitive))
                    {
                        this.JsonSchema_0.AdditionalProperties = this.method_5(type4, Required.Default, false);
                    }
                    goto Label_04CD;

                case Enum15.Dynamic:
                case Enum15.Linq:
                    this.JsonSchema_0.Type = 0x7f;
                    goto Label_04CD;

                case Enum15.Serializable:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                    this.method_9(class4.type_0, (JsonISerializableContract)contract);
                    goto Label_04CD;
                }
                throw new JsonException("Unexpected contract type: {0}".smethod_0(CultureInfo.InvariantCulture, contract));
            }
Label_04CD:
            return(this.method_1().JsonSchema_0);
        }