Пример #1
0
        private bool TryCreateImplicitSorting(
            PropertyInfo property,
            [NotNullWhen(true)] out SortOperationDefintion?definition)
        {
            Type type = property.PropertyType;

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

            if (typeof(IComparable).IsAssignableFrom(type))
            {
                definition = SortOperationDescriptor
                             .CreateOperation(property, Context)
                             .CreateDefinition();
                return(true);
            }

            if (Context.TypeInspector.TryCreateTypeInfo(type, out ITypeInfo? typeInfo) &&
                typeInfo.GetExtendedType()?.IsList is {} isList)
            {
                if (type.IsClass && !isList)
                {
                    definition = SortObjectOperationDescriptor
                                 .CreateOperation(property, Context)
                                 .CreateDefinition();
                    return(true);
                }
            }

            definition = null;
            return(false);
        }
Пример #2
0
        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);
        }
        public ISortObjectOperationDescriptor <TObject> SortableObject <TObject>(
            Expression <Func <T, TObject> > property)
            where TObject : class
        {
            if (property.ExtractMember() is PropertyInfo p)
            {
                return(Fields.GetOrAddDescriptor(p,
                                                 () => SortObjectOperationDescriptor <TObject> .CreateOperation(p, Context)));
            }

            // TODO : resources
            throw new ArgumentException(
                      "Only properties are allowed for input types.",
                      nameof(property));
        }
Пример #4
0
        public ISortObjectOperationDescriptor <TObject> SortableObject <TObject>(
            Expression <Func <T, TObject> > property)
            where TObject : class
        {
            if (property.ExtractMember() is PropertyInfo p)
            {
                return(Fields.GetOrAddDescriptor(p,
                                                 () => SortObjectOperationDescriptor <TObject> .CreateOperation(p, Context)));
            }

            // TODO : resources
            throw new ArgumentException(
                      SortingResources.SortInputTypeDescriptor_Ignore_OnlyPopertiesAreAllowed,
                      nameof(property));
        }
Пример #5
0
        private bool TryCreateImplicitSorting(
            PropertyInfo property,
            out SortOperationDefintion definition)
        {
            if (typeof(IComparable).IsAssignableFrom(property.PropertyType))
            {
                definition = SortOperationDescriptor
                             .CreateOperation(property, Context)
                             .CreateDefinition();
                return(true);
            }
            if (
                property.PropertyType.IsClass &&
                !typeof(IEnumerable <>).IsAssignableFrom(property.PropertyType))
            {
                definition = SortObjectOperationDescriptor
                             .CreateOperation(property, Context)
                             .CreateDefinition();
                return(true);
            }

            definition = null;
            return(false);
        }