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)));
        }
        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)));
        }
        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)));
        }
        public static ISchemaCombinator?GetSchemaCombinator(this ISchema schema, CombinatorType combinatorType)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            string combinatorName = combinatorType.ToString();

            return(schema.GetMetadata <ISchemaCombinator>(combinatorName));
        }
        public static INumericInterval?GetNumericInterval(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <INumericInterval>());
        }
        public static IStringPattern?GetStringPattern(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IStringPattern>());
        }
        /// <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>());
        }
        /// <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));
        }
        public static IStringMinLength?GetStringMinLength(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetSchemaMetadata <IStringMinLength>());
        }
        public static IListItemSchema?GetLisItemsSchema(this ISchema schema)
        {
            schema.AssertArgumentNotNull(nameof(schema));

            return(schema.GetMetadata <IListItemSchema>());
        }
        public static INullability GetOrEvaluateNullability(this ISchema property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetNullability() ?? (property.Type.CanAcceptNull() ? AllowNull.Instance : DisallowNull.Instance));
        }
        public static INullability?GetNullability(this ISchema property)
        {
            property.AssertArgumentNotNull(nameof(property));

            return(property.GetSchemaMetadata <INullability>());
        }
        /// <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;
        }
        /// <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;
        }