private bool TryCreateImplicitSorting( PropertyInfo property, out SortOperationDefintion definition) { Type type = property.PropertyType; if (type.IsGenericType && System.Nullable.GetUnderlyingType(type) is Type nullableType) { type = nullableType; } if (typeof(IComparable).IsAssignableFrom(type)) { definition = SortOperationDescriptor .CreateOperation(property, Context) .CreateDefinition(); return(true); } if (type.IsClass && !DotNetTypeInfoFactory.IsListType(type)) { definition = SortObjectOperationDescriptor .CreateOperation(property, Context) .CreateDefinition(); return(true); } definition = null; return(false); }
private bool TryGetTypeOfRuntimeType( Type runtimeType, [NotNullWhen(true)] out Type?type) { if (runtimeType.IsGenericType && System.Nullable.GetUnderlyingType(runtimeType) is { } nullableType) { runtimeType = nullableType; } if (Bindings.TryGetValue(runtimeType, out type)) { return(true); } if (DotNetTypeInfoFactory.IsListType(runtimeType)) { if (!TypeInspector.Default.TryCreate(runtimeType, out Utilities.TypeInfo typeInfo)) { throw new ArgumentException( string.Format("The type {0} is unknown", runtimeType.Name), nameof(runtimeType)); } if (TryGetTypeOfRuntimeType(typeInfo.ClrType, out Type? clrType)) { type = typeof(ListFilterInput <>).MakeGenericType(clrType); return(true); } } if (runtimeType.IsEnum) { type = typeof(EnumOperationInput <>).MakeGenericType(runtimeType); return(true); } if (runtimeType.IsClass) { type = typeof(FilterInputType <>).MakeGenericType(runtimeType); return(true); } type = null; return(false); }
private static bool TryCreateArrayFilter( IDescriptorContext context, Type type, PropertyInfo property, IFilterConvention filterConventions, [NotNullWhen(true)] out FilterFieldDefintion?definition) { 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)) { elementType = typeof(ISingleFilter <>).MakeGenericType(elementType); } field = new ArrayFilterFieldDescriptor(context, property, elementType, filterConventions); 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); }