/// <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> public static ObjectFilterOperationDescriptor New( IDescriptorContext context, ObjectFilterFieldDescriptor descriptor, NameString name, ITypeReference type, FilterOperation operation) => new ObjectFilterOperationDescriptor( 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 ObjectFilterOperationDescriptor <TObject> New( IDescriptorContext context, ObjectFilterFieldDescriptor <TObject> descriptor, NameString name, ITypeReference type, FilterOperation operation, IFilterConvention filterConventions) => new ObjectFilterOperationDescriptor <TObject>( context, descriptor, name, type, operation, filterConventions);
protected ObjectFilterOperationDescriptor( IDescriptorContext context, ObjectFilterFieldDescriptor <TObject> descriptor, NameString name, ITypeReference type, FilterOperation operation, IFilterConvention filterConventions) : base(context, descriptor, name, type, operation, filterConventions) { _descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor)); }
public IObjectFilterFieldDescriptor <TObject> Filter <TObject>( Expression <Func <T, TObject> > property) where TObject : class { if (property.ExtractMember() is PropertyInfo p) { var field = new ObjectFilterFieldDescriptor <TObject>(Context, p); Fields.Add(field); return(field); } throw new ArgumentException( FilterResources.FilterInputTypeDescriptor_OnlyProperties, nameof(property)); }
protected ObjectFilterOperationDescriptor( IDescriptorContext context, ObjectFilterFieldDescriptor 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)); }
private bool TryCreateImplicitFilter( PropertyInfo property, out FilterFieldDefintion definition) { if (property.PropertyType == typeof(string)) { var field = new StringFilterFieldDescriptor(Context, property); definition = field.CreateDefinition(); return(true); } if (property.PropertyType == typeof(bool) || property.PropertyType == 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 (property.PropertyType.IsClass) { var field = new ObjectFilterFieldDescriptor( Context, property, property.PropertyType); definition = field.CreateDefinition(); return(true); } definition = null; return(false); }
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); }
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); }
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); }