예제 #1
0
        private IEnumerable <OverloadInfo> GetOverloadsForProperty(Property property)
        {
            if (property.ValueType.IsSchemaFromType)
            {
                JsonSchemaType type = property.ValueType.JsonTypes;

                if (type.HasFlag(JsonSchemaType.Object) ||
                    type.HasFlag(JsonSchemaType.Array) ||
                    type.HasFlag(JsonSchemaType.Null) ||
                    type.HasFlag(JsonSchemaType.Any) ||
                    type == JsonSchemaType.None)
                {
                    throw new Exception(string.Format("Property '{0}' does not specify a $ref to a schema, nor is it a simple JSON type.", property.Name));
                }

                if (type.HasFlag(JsonSchemaType.String))
                {
                    yield return(s_defaultStringOverload);
                }

                if (type.HasFlag(JsonSchemaType.Float))
                {
                    yield return(s_defaultDoubleOverload);
                }

                if (type.HasFlag(JsonSchemaType.Integer))
                {
                    yield return(s_defaultIntegerOverload);
                }

                if (type.HasFlag(JsonSchemaType.Boolean))
                {
                    yield return(s_defaultBooleanOverload);
                }
            }
            else
            {
                OverloadInfo[] overloads;
                if (m_configuration.Types.TryGetValue(property.ValueType.Name, out overloads))
                {
                    foreach (OverloadInfo overload in overloads)
                    {
                        yield return(overload);
                    }
                }
                else
                {
                    yield return(OverloadInfo.CreateDefault(property.ValueType.NameWithPascalCase));
                }
            }
        }
예제 #2
0
        private OverloadInfo[] GetOverloadsForProperty(Property property)
        {
            OverloadInfo[] overloads;

            if (property.ValueType.IsSchemaFromType)
            {
                overloads = new OverloadInfo[4];

                int            index = 0;
                JsonSchemaType type  = property.ValueType.JsonTypes;

                if ((type & JsonSchemaType.String) == JsonSchemaType.String)
                {
                    overloads[index++] = s_defaultStringOverload;
                }
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Float)
                {
                    overloads[index++] = s_defaultDoubleOverload;
                }
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Integer)
                {
                    overloads[index++] = s_defaultIntegerOverload;
                }
                if ((type & JsonSchemaType.Boolean) == JsonSchemaType.Boolean)
                {
                    overloads[index++] = s_defaultBooleanOverload;
                }
                if ((type & JsonSchemaType.Object) == JsonSchemaType.Object ||
                    (type & JsonSchemaType.Array) == JsonSchemaType.Array ||
                    (type & JsonSchemaType.Null) == JsonSchemaType.Null ||
                    (type & JsonSchemaType.Any) == JsonSchemaType.Any ||
                    type == JsonSchemaType.None)
                {
                    throw new Exception(string.Format("Property '{0}' does not specify a $ref to a schema, nor is it a simple JSON type.", property.Name));
                }

                Array.Resize(ref overloads, index);
            }
            else
            {
                if (!m_configuration.Types.TryGetValue(property.ValueType.Name, out overloads))
                {
                    overloads = new[] { OverloadInfo.CreateDefault(property.ValueType.NameWithPascalCase) };
                    m_configuration.Types[property.ValueType.Name] = overloads;
                }
            }
            return(overloads);
        }