/// <summary>
 /// Create a new boolean filter operation descriptor.
 /// </summary>
 /// <param name="context">
 /// The descriptor context.
 /// </param>
 /// <param name="descriptor">
 /// The field descriptor on which this
 /// filter operation shall be applied.
 /// </param>
 /// <param name="name">
 /// The default name of the filter operation field.
 /// </param>
 /// <param name="type">
 /// The field type of this filter operation field.
 /// </param>
 /// <param name="operation">
 /// The filter operation info.
 /// </param>
 public static ArrayBooleanFilterOperationDescriptor New(
     IDescriptorContext context,
     ArrayFilterFieldDescriptor descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation) =>
 new ArrayBooleanFilterOperationDescriptor(
     context, descriptor, name, type, operation);
 /// <summary>
 /// Create a new string filter operation descriptor.
 /// </summary>
 /// <param name="context">
 /// The descriptor context.
 /// </param>
 /// <param name="descriptor">
 /// The field descriptor on which this
 /// filter operation shall be applied.
 /// </param>
 /// <param name="name">
 /// The default name of the filter operation field.
 /// </param>
 /// <param name="type">
 /// The field type of this filter operation field.
 /// </param>
 /// <param name="operation">
 /// The filter operation info.
 /// </param>
 /// <param name="filterConventions">
 /// The filter conventions
 /// </param>
 public static ArrayFilterOperationDescriptor <TArray> New(
     IDescriptorContext context,
     ArrayFilterFieldDescriptor <TArray> descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation,
     IFilterConvention filterConvention) =>
 new ArrayFilterOperationDescriptor <TArray>(
     context, descriptor, name, type, operation, filterConvention);
 protected ArrayBooleanFilterOperationDescriptor(
     IDescriptorContext context,
     ArrayFilterFieldDescriptor descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation) : base(context, name, type, operation)
 {
     _descriptor = descriptor
                   ?? throw new ArgumentNullException(nameof(descriptor));
 }
 protected ArrayFilterOperationDescriptor(
     IDescriptorContext context,
     ArrayFilterFieldDescriptor <TArray> descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation,
     IFilterConvention filterConventions)
     : base(context, descriptor, name, type, operation, filterConventions)
 {
     _descriptor = descriptor
                   ?? throw new ArgumentNullException(nameof(descriptor));
 }
Exemple #5
0
        public IArrayFilterFieldDescriptor <TObject> ListFilter <TObject, TListType>(
            Expression <Func <T, TListType> > property)
        {
            if (property.ExtractMember() is PropertyInfo p)
            {
                var field = new ArrayFilterFieldDescriptor <TObject>(Context, p);
                Fields.Add(field);
                return(field);
            }

            throw new ArgumentException(
                      FilterResources.FilterInputTypeDescriptor_OnlyProperties,
                      nameof(property));
        }
 protected ArrayFilterOperationDescriptor(
     IDescriptorContext context,
     ArrayFilterFieldDescriptor descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation)
     : base(context)
 {
     Definition.Name = name.EnsureNotEmpty(nameof(name));
     Definition.Type = type
                       ?? throw new ArgumentNullException(nameof(type));
     Definition.Operation = operation
                            ?? throw new ArgumentNullException(nameof(operation));
     _descriptor = descriptor
                   ?? throw new ArgumentNullException(nameof(descriptor));
 }
Exemple #7
0
        private bool TryCreateImplicitFilter(
            PropertyInfo property,
            out FilterFieldDefintion definition)
        {
            Type type = property.PropertyType;

            if (type.IsGenericType && Nullable.GetUnderlyingType(type) is Type nullableType)
            {
                type = nullableType;
            }

            if (type == typeof(string))
            {
                var field = new StringFilterFieldDescriptor(Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (type == typeof(bool))
            {
                var field = new BooleanFilterFieldDescriptor(
                    Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (IsComparable(property.PropertyType))
            {
                var field = new ComparableFilterFieldDescriptor(
                    Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (DotNetTypeInfoFactory.IsListType(type))
            {
                if (!TypeInspector.Default.TryCreate(type, out Utilities.TypeInfo typeInfo))
                {
                    throw new ArgumentException(
                              FilterResources.FilterArrayFieldDescriptor_InvalidType,
                              nameof(property));
                }

                Type elementType = typeInfo.ClrType;
                ArrayFilterFieldDescriptor field;

                if (elementType == typeof(string) ||
                    elementType == typeof(bool) ||
                    typeof(IComparable).IsAssignableFrom(elementType))
                {
                    field = new ArrayFilterFieldDescriptor(
                        Context,
                        property,
                        typeof(ISingleFilter <>).MakeGenericType(elementType));
                }
                else
                {
                    field = new ArrayFilterFieldDescriptor(Context, property, elementType);
                }

                definition = field.CreateDefinition();
                return(true);
            }

            if (type.IsClass)
            {
                var field = new ObjectFilterFieldDescriptor(
                    Context, property, property.PropertyType);
                definition = field.CreateDefinition();
                return(true);
            }

            definition = null;
            return(false);
        }
Exemple #8
0
        private bool TryCreateImplicitFilter(
            PropertyInfo property,
            [NotNullWhen(true)] out FilterFieldDefintion?definition)
        {
            Type type = property.PropertyType;

            if (type.IsGenericType &&
                System.Nullable.GetUnderlyingType(type) is { } nullableType)
            {
                type = nullableType;
            }

            if (type == typeof(string))
            {
                var field = new StringFilterFieldDescriptor(Context, property);
                field.BindFilters(Definition.Fields.BindingBehavior);
                definition = field.CreateDefinition();
                return(true);
            }

            if (type == typeof(bool))
            {
                var field = new BooleanFilterFieldDescriptor(
                    Context,
                    property);
                field.BindFilters(Definition.Fields.BindingBehavior);
                definition = field.CreateDefinition();
                return(true);
            }

            if (IsComparable(property.PropertyType))
            {
                var field = new ComparableFilterFieldDescriptor(
                    Context,
                    property);
                field.BindFilters(Definition.Fields.BindingBehavior);
                definition = field.CreateDefinition();
                return(true);
            }

            if (Context.TypeInspector.TryCreateTypeInfo(type, out ITypeInfo? typeInfo) &&
                typeInfo.GetExtendedType()?.ElementType?.Source is { } elementType)
            {
                ArrayFilterFieldDescriptor field;

                if (elementType == typeof(string) ||
                    elementType == typeof(bool) ||
                    typeof(IComparable).IsAssignableFrom(elementType))
                {
                    field = new ArrayFilterFieldDescriptor(
                        Context,
                        property,
                        typeof(ISingleFilter <>).MakeGenericType(elementType));
                }
                else
                {
                    field = new ArrayFilterFieldDescriptor(Context, property, elementType);
                }

                field.BindFilters(Definition.Fields.BindingBehavior);
                definition = field.CreateDefinition();
                return(true);
            }

            if (type.IsClass)
            {
                var field = new ObjectFilterFieldDescriptor(
                    Context,
                    property,
                    property.PropertyType);
                field.BindFilters(Definition.Fields.BindingBehavior);
                definition = field.CreateDefinition();
                return(true);
            }

            definition = null;
            return(false);
        }
Exemple #9
0
        private bool TryCreateImplicitFilter(
            PropertyInfo property,
            out FilterFieldDefintion definition)
        {
            var type = property.PropertyType;

            if (type.IsGenericType && Nullable.GetUnderlyingType(type) is Type nullableType)
            {
                type = nullableType;
            }

            if (type == typeof(string))
            {
                var field = new StringFilterFieldDescriptor(Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (type == typeof(bool))
            {
                var field = new BooleanFilterFieldDescriptor(
                    Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (IsComparable(property.PropertyType))
            {
                var field = new ComparableFilterFieldDescriptor(
                    Context, property);
                definition = field.CreateDefinition();
                return(true);
            }

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                ArrayFilterFieldDescriptor field;

                var genericTypeArgument = type.GetGenericArguments()[0];

                if (genericTypeArgument.IsGenericType &&
                    Nullable.GetUnderlyingType(genericTypeArgument) is Type nullableEnumerableType)
                {
                    genericTypeArgument = nullableEnumerableType;
                }
                if (genericTypeArgument == typeof(string) ||
                    genericTypeArgument == typeof(bool) ||
                    genericTypeArgument == typeof(bool?) ||
                    typeof(IComparable).IsAssignableFrom(genericTypeArgument))
                {
                    field = new ArrayFilterFieldDescriptor(
                        Context,
                        property,
                        typeof(ISingleFilter <>).MakeGenericType(genericTypeArgument)
                        );
                }
                else
                {
                    field = new ArrayFilterFieldDescriptor(Context, property, genericTypeArgument);
                }
                definition = field.CreateDefinition();
                return(true);
            }

            if (type.IsClass)
            {
                var field = new ObjectFilterFieldDescriptor(
                    Context, property, property.PropertyType);
                definition = field.CreateDefinition();
                return(true);
            }

            definition = null;
            return(false);
        }