Esempio n. 1
0
        private static Property ResolveProperty(object @object, PropertyInfo propertyInfo, IPropertyDescriptionBuilder propertyDescriptionBuilder,
                                                ICustomPropertyConfigurationProvider customPropertyConfigurationProvider)
        {
            var configuration = @object == null
                                    ? customPropertyConfigurationProvider?.TryGetConfiguration(propertyInfo)
                                    : customPropertyConfigurationProvider?.TryGetConfiguration(@object, propertyInfo);

            var typeInfo = ResolveType(null, configuration?.ResolvedType ?? propertyInfo.PropertyType,
                                       propertyDescriptionBuilder, customPropertyConfigurationProvider);

            return(new Property
            {
                TypeInfo = typeInfo,
                Description = propertyDescriptionBuilder.Build(propertyInfo, configuration?.ResolvedType ?? propertyInfo.PropertyType),
            });
        }
Esempio n. 2
0
        private static PropertyMetaInformation BuildPropertyInfo(object? @object, PropertyInfo propertyInfo,
                                                                 IPropertyDescriptionBuilder propertyDescriptionBuilder,
                                                                 ICustomPropertyConfigurationProvider? propertyConfigurationProvider,
                                                                 Type[] types)
        {
            object? objectProperty;
            Type propertyType;
            Type originalPropertyType;
            if (@object == null)
            {
                var customConfiguration = propertyConfigurationProvider?.TryGetConfiguration(propertyInfo);
                objectProperty = null;
                propertyType = customConfiguration?.ResolvedType ?? propertyInfo.PropertyType;
                originalPropertyType = propertyInfo.PropertyType;
            }
            else
            {
                var customConfiguration = propertyConfigurationProvider?.TryGetConfiguration(@object, propertyInfo);
                var underlyingProperty = propertyInfo.GetValue(@object);
                objectProperty = customConfiguration != null ? customConfiguration.StoredToApi(underlyingProperty) : underlyingProperty;
                var resolvedType = customConfiguration?.ResolvedType ?? propertyInfo.PropertyType;
                var objectPropertyType = IsSimpleType(resolvedType) ? null : objectProperty?.GetType();
                propertyType = objectPropertyType ?? resolvedType;
                originalPropertyType = underlyingProperty?.GetType() ?? propertyInfo.PropertyType;
            }

            var underlyingType = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? propertyType.GetGenericArguments()[0] : propertyType;
            var propertyDescription = propertyDescriptionBuilder.Build(propertyInfo, propertyType);
            return new PropertyMetaInformation
                {
                    Name = propertyInfo.Name,
                    AvailableFilters = propertyDescription.AvailableFilters,
                    AvailableValues = underlyingType.IsEnum ? Enum.GetNames(underlyingType) : new string[0],
                    IsEditable = propertyInfo.SetMethod != null,
                    IsIdentity = propertyDescription.IsIdentity,
                    IsRequired = propertyDescription.IsRequired,
                    IsSearchable = propertyDescription.IsSearchable,
                    IsSortable = propertyDescription.IsSortable,
                    Type = BuildTypeMetaInformation(objectProperty, propertyType, originalPropertyType, propertyDescriptionBuilder, @object == null ? null : propertyConfigurationProvider, types),
                };
        }
Esempio n. 3
0
        private static PropertyMetaInformation BuildPropertyInfo(object @object, [NotNull] PropertyInfo propertyInfo,
                                                                 IPropertyDescriptionBuilder propertyDescriptionBuilder,
                                                                 ICustomPropertyConfigurationProvider propertyConfigurationProvider,
                                                                 [NotNull, ItemNotNull] Type[] types)
        {
            var customConfiguration = @object == null
                                          ? propertyConfigurationProvider.TryGetConfiguration(propertyInfo)
                                          : propertyConfigurationProvider.TryGetConfiguration(@object, propertyInfo);

            var propertyType        = customConfiguration?.ResolvedType ?? propertyInfo.PropertyType;
            var propertyDescription = propertyDescriptionBuilder.Build(propertyInfo, propertyType);

            return(new PropertyMetaInformation
            {
                Name = propertyInfo.Name,
                AvailableFilters = propertyDescription.AvailableFilters,
                IsIdentity = propertyDescription.IsIdentity,
                IsRequired = propertyDescription.IsRequired,
                IsSearchable = propertyDescription.IsSearchable,
                IsSortable = propertyDescription.IsSortable,
                Type = BuildTypeMetaInformation(propertyType, propertyDescriptionBuilder, propertyConfigurationProvider, types),
            });
        }