コード例 #1
0
        public static ISchema <T> SetMaximum <T>(this ISchema <T> schema, T maximum, bool exclusiveMaximum = false)
        {
            schema.AssertArgumentNotNull(nameof(schema));
            schema.AssertPropertyIsNumeric();

            return(schema.MergeNumericInterval(new NumericInterval(null, null, Convert.ToDecimal(maximum), exclusiveMaximum: exclusiveMaximum)));
        }
コード例 #2
0
        public static ISchema <T> GreaterThan <T>(this ISchema <T> schema, T minimum)
        {
            schema.AssertArgumentNotNull(nameof(schema));
            schema.AssertPropertyIsNumeric();

            return(schema.MergeNumericInterval(new NumericInterval(Convert.ToDecimal(minimum), exclusiveMinimum: true, null, null)));
        }
コード例 #3
0
        public static ISchema <T> LessThanOrEqual <T>(this ISchema <T> schema, T maximum)
        {
            schema.AssertArgumentNotNull(nameof(schema));
            schema.AssertPropertyIsNumeric();

            return(schema.MergeNumericInterval(new NumericInterval(null, null, Convert.ToDecimal(maximum), exclusiveMaximum: false)));
        }
コード例 #4
0
        public static ISchemaCombinator?GetSchemaCombinator(this ISchema schema, CombinatorType combinatorType)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            string combinatorName = combinatorType.ToString();

            return(schema.GetMetadata <ISchemaCombinator>(combinatorName));
        }
コード例 #5
0
        public static INumericInterval?GetNumericInterval(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <INumericInterval>());
        }
コード例 #6
0
        public static IStringPattern?GetStringPattern(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IStringPattern>());
        }
コード例 #7
0
        /// <summary>
        /// Gets <see cref="ISchemaProperties"/> for <see cref="ISchema"/>.
        /// </summary>
        /// <param name="schema">Source schema.</param>
        /// <returns>Optional <see cref="ISchemaProperties"/> metadata.</returns>
        public static ISchemaProperties?GetSchemaProperties(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetMetadata <ISchemaProperties>());
        }
コード例 #8
0
        /// <summary>
        /// Adds <see cref="ISchemaProperties"/> metadata to schema.
        /// </summary>
        /// <param name="schema">Target schema.</param>
        /// <param name="schemaProperties">Schema properties to add to the schema..</param>
        /// <returns>The same schema.</returns>
        public static ISchema SetProperties(this ISchema schema, ISchemaProperties schemaProperties)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.SetMetadata(schemaProperties));
        }
コード例 #9
0
        public static IStringMinLength?GetStringMinLength(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IStringMinLength>());
        }
コード例 #10
0
        public static IListItemSchema?GetLisItemsSchema(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetMetadata <IListItemSchema>());
        }
コード例 #11
0
        public static INullability GetOrEvaluateNullability(this ISchema property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetNullability() ?? (property.Type.CanAcceptNull() ? AllowNull.Instance : DisallowNull.Instance));
        }
コード例 #12
0
        public static INullability?GetNullability(this ISchema property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetSchemaMetadata <INullability>());
        }
コード例 #13
0
        /// <summary>
        /// Gets optional <see cref="IRequired"/> metadata.
        /// </summary>
        /// <param name="schema">Source property.</param>
        /// <returns>Optional <see cref="IRequired"/>.</returns>
        public static IRequired?GetRequired(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IRequired>());
        }
コード例 #14
0
        public static IAllowedValues?GetAllowedValuesUntyped(this ISchema property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetSchemaMetadata <IAllowedValues>());
        }
コード例 #15
0
        public static IAllowedValues <T>?GetAllowedValues <T>(this ISchema <T> property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetSchemaMetadata <IAllowedValues>() as IAllowedValues <T>);
        }
コード例 #16
0
        public static IListMaxItems?GetListMaxItems(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IListMaxItems>());
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HasSchema"/> class.
        /// </summary>
        /// <param name="schema">Schema for <see cref="IPropertyContainer"/>.</param>
        public HasSchema(ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            Schema = schema;
        }
コード例 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListItemSchema"/> class.
        /// </summary>
        /// <param name="itemSchema">Schema to validate list item.</param>
        public ListItemSchema(ISchema itemSchema)
        {
            itemSchema.AssertArgumentNotNull(nameof(itemSchema));

            ItemSchema = itemSchema;
        }