private SortColumnConfiguration CreateByDefinition(IListDefinition source) { PropertyInfo requestProperty; PropertyInfo resultProperty; if (source.SortColumnDefinition.RequestProperty != null) { requestProperty = source.SortColumnDefinition.RequestProperty; resultProperty = source.SortColumnDefinition.ResultProperty ?? source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name) || x.Name.Equals(options.SortColumnPropertyName)) ?? throw new PropertyNotFoundException($"The sort column property on '{source.ResultType.Name}' is unspecified and no property named '{requestProperty.Name}' has been defined."); return(new SortColumnConfiguration(requestProperty, resultProperty, source.SortColumnDefinition.DefaultValue)); } else { requestProperty = source.RequestProperties.FirstOrDefault(x => x.Name.Equals(options.SortColumnPropertyName)); } if (requestProperty == null) { return(new SortColumnConfiguration(options.SortColumnPropertyName, source.SortColumnDefinition.DefaultValue)); } resultProperty = source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name) || x.Name.Equals(options.SortColumnPropertyName)) ?? throw new PropertyNotFoundException($"The sort column property on '{source.ResultType.Name}' is unspecified and no property named '{requestProperty.Name}' has been defined."); var defaultValue = source.SortColumnDefinition.DefaultValue ?? requestProperty.GetDefaultValue <object>(); return(new SortColumnConfiguration(requestProperty, resultProperty, defaultValue)); }
public IModelActivatorConfiguration Create(IListDefinition source) { if (source.ModelActivatorDefinition == null) { return(defaultConfiguration); } var definition = source.ModelActivatorDefinition; if (definition.Method != null) { return(new ModelActivatorConfiguration(definition.Method)); } if (definition.FactoryType != null) { return(new ModelActivatorConfiguration(definition.FactoryType)); } if (definition.Factory != null) { return(new ModelActivatorConfiguration(definition.Factory)); } return(defaultConfiguration); }
public IListConfiguration Create(IListDefinition source) { var configuration = new ListConfiguration(source.RequestType, source.ItemType, source.ResultType); var completedProperties = new List <PropertyInfo>(); foreach (var property in source.RequestProperties) { if (!IsSearchProperty(property)) { continue; } var searchConfiguration = searchConfigurationFactory.Create(property, source); configuration.SearchConfigurations.Add(searchConfiguration); completedProperties.Add(property); } configuration.PageConfiguration = pageConfigurationFactory.Create(source); if (configuration.PageConfiguration?.RequestProperty != null) { completedProperties.Add(configuration.PageConfiguration.RequestProperty); } configuration.RowsConfiguration = rowsConfigurationFactory.Create(source); if (configuration.RowsConfiguration?.RequestProperty != null) { completedProperties.Add(configuration.RowsConfiguration.RequestProperty); } configuration.SortColumnConfiguration = sortColumnConfigurationFactory.Create(source); if (configuration.SortColumnConfiguration?.RequestProperty != null) { completedProperties.Add(configuration.SortColumnConfiguration.RequestProperty); } configuration.SortDirectionConfiguration = sortDirectionConfigurationFactory.Create(source); if (configuration.SortDirectionConfiguration?.RequestProperty != null) { completedProperties.Add(configuration.SortDirectionConfiguration.RequestProperty); } foreach (var requestProperty in source.RequestProperties.Where(x => !completedProperties.Contains(x))) { var propertyConfiguration = propertyConfigurationFactory.Create(requestProperty, source); if (propertyConfiguration == null) { continue; } configuration.PropertyConfigurations.Add(propertyConfiguration); } configuration.PostRedirectGetConfiguration = postRedirectGetConfigurationFactory.Create(source); configuration.TransferValuesConfiguration = transferValuesConfigurationFactory.Create(source); configuration.ModelActivatorConfiguration = modelActivatorConfigurationFactory.Create(source); return(configuration); }
public PropertyConfiguration Create(PropertyInfo requestProperty, IListDefinition source) { if (source.PropertyDefinitions.TryGetValue(requestProperty, out var definition)) { return(CreateByDefinition(source, definition)); } return(CreateByConvention(requestProperty, source)); }
public RowsConfiguration Create(IListDefinition source) { if (source.RowsDefinition != null) { return(CreateByDefinition(source)); } return(CreateByConvention(source)); }
public SortColumnConfiguration Create(IListDefinition source) { if (source.SortColumnDefinition != null) { return(CreateByDefinition(source)); } return(CreateByConvention(source)); }
private RowsConfiguration CreateByConvention(IListDefinition source) { var requestProperty = source.RequestProperties.FirstOrDefault(x => x.Name.Equals(options.RowsPropertyName)); if (requestProperty == null) { return(null); } var resultProperty = source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name) || x.Name.Equals(options.RowsPropertyName)) ?? throw new PropertyNotFoundException($"The rows property on '{source.ResultType.Name}' is unspecified and no property named '{requestProperty.Name}' has been defined."); var defaultValue = requestProperty.GetDefaultValue <int?>() ?? options.DefaultRows; return(new RowsConfiguration(requestProperty, resultProperty, defaultValue)); }
private RowsConfiguration CreateByDefinition(IListDefinition source) { PropertyInfo requestProperty; PropertyInfo resultProperty; if (source.RowsDefinition.RequestProperty != null) { requestProperty = source.RowsDefinition.RequestProperty; resultProperty = source.RowsDefinition.ResultProperty ?? source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name) || x.Name.Equals(options.RowsPropertyName)) ?? throw new PropertyNotFoundException($"The rows property on '{source.ResultType.Name}' is unspecified and no property named '{requestProperty.Name}' has been defined."); return(new RowsConfiguration(requestProperty, resultProperty, source.RowsDefinition.DefaultValue ?? options.DefaultRows)); } if (!string.IsNullOrWhiteSpace(source.RowsDefinition.Name)) { requestProperty = source.RequestProperties.FirstOrDefault(x => x.Name.Equals(source.RowsDefinition.Name)); if (requestProperty == null) { return(new RowsConfiguration(source.RowsDefinition.Name, source.RowsDefinition.DefaultValue ?? options.DefaultRows)); } } else { requestProperty = source.RequestProperties.FirstOrDefault(x => x.Name.Equals(options.RowsPropertyName)); } if (requestProperty == null) { return(new RowsConfiguration(options.RowsPropertyName, source.RowsDefinition.DefaultValue ?? options.DefaultRows)); } resultProperty = source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name) || x.Name.Equals(options.RowsPropertyName)) ?? throw new PropertyNotFoundException($"The rows property on '{source.ResultType.Name}' is unspecified and no property named '{requestProperty.Name}' has been defined."); var defaultValue = source.RowsDefinition.DefaultValue ?? requestProperty.GetDefaultValue <int?>() ?? options.DefaultRows; return(new RowsConfiguration(requestProperty, resultProperty, defaultValue)); }
private PropertyConfiguration CreateByDefinition(IListDefinition source, IPropertyDefinition definition) { var requestProperty = definition.RequestProperty; Debug.Assert(requestProperty != null, nameof(requestProperty) + " != null"); var resultProperty = definition.ResultProperty ?? source.ResultProperties.FirstOrDefault(x => x.Name.Equals(definition.RequestProperty.Name)); var ignored = definition.Ignore.GetValueOrDefault(false); if (!ignored && resultProperty != null && !resultProperty.PropertyType.IsAssignableFrom(requestProperty.PropertyType)) { throw new PropertyTypeMismatchException($"The request property {requestProperty.Name} type '{requestProperty.PropertyType.FullName}' is not assignable to '{resultProperty.PropertyType.FullName}'"); } var defaultValue = definition.DefaultValue ?? requestProperty.GetDefaultValue <object>(); return(new PropertyConfiguration(definition.RequestProperty, resultProperty, defaultValue, ignored)); }
private PropertyConfiguration CreateByConvention(PropertyInfo requestProperty, IListDefinition source) { var resultProperty = source.ResultProperties.FirstOrDefault(x => x.Name.Equals(requestProperty.Name)); if (resultProperty == null) { return(null); } if (!resultProperty.PropertyType.IsAssignableFrom(requestProperty.PropertyType)) { throw new PropertyTypeMismatchException($"The request property {requestProperty.Name} type '{requestProperty.PropertyType.FullName}' is not assignable to '{resultProperty.PropertyType.FullName}'"); } var defaultValue = requestProperty.GetDefaultValue <object>(); return(new PropertyConfiguration(requestProperty, resultProperty, defaultValue, false)); }
public TransferValuesConfiguration Create(IListDefinition definition) => new TransferValuesConfiguration(definition.TransferValuesDefinition?.ActionName ?? options.ListActionName, definition.TransferValuesDefinition?.Enabled ?? options.TransferValuesEnabled);
public PostRedirectGetConfiguration Create(IListDefinition definition) => new PostRedirectGetConfiguration(definition.PostRedirectGetDefinition?.ActionName ?? options.ListActionName, definition.PostRedirectGetDefinition?.Enabled ?? options.PostRedirectGetEnabled);