Beispiel #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));
                }
            }
        }
        public static JsonValue ToJson(this JsonSchemaType type)
        {
            var allValues = Enum.GetValues(typeof(JsonSchemaType)).Cast <JsonSchemaType>()
                            .Where(v => v != JsonSchemaType.NotDefined);
            var types = allValues.Where(v => type.HasFlag(v))
                        .Select(_TranslateSingleType)
                        .ToList();

            return(types.Count == 1
                                       ? types[0]
                                       : types.ToJson());
        }
        public static JsonValue ToJson(this JsonSchemaType type)
        {
            var allValues = Enum.GetValues(typeof(JsonSchemaType)).Cast <JsonSchemaType>()
                            .Where(v => v != JsonSchemaType.NotDefined);
            var types = allValues.Where(v => type.HasFlag(v))
                        .Select(_TranslateSingleType)
                        .ToList();

            if (types.Count == 1)
            {
                return(types[0]);
            }

            var array = types.ToJson();

            array.Array.EqualityStandard = ArrayEquality.ContentsEqual;

            return(array);
        }
Beispiel #4
0
        private static bool PropertyValueIsLeaf(Property property)
        {
            JsonSchemaType jsonTypes = property.ValueType.JsonTypes;

            return(!jsonTypes.HasFlag(JsonSchemaType.Object));
        }