private List <UrlParameter> GetUrlParameters(BehaviorChain chain) { var action = chain.FirstCall(); var properties = _typeCache.GetPropertiesFor(action.InputType()); return(action.ParentChain().Route.Input.RouteParameters.Select( x => { var property = properties[x.Name]; var description = _memberConvention.GetDescription(property); return _configuration.UrlParameterOverrides.Apply(chain, property, new UrlParameter { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), Type = property.PropertyType.GetXmlName(_configuration.EnumFormat == EnumFormat.AsString), Options = _optionFactory.BuildOptions(property.PropertyType) }); }).ToList()); }
private List <TypeContext> GetTypes(TypeContext type) { var properties = type.Type.IsProjection() ? type.Type.GetProjectionProperties() : _typeCache.GetPropertiesFor(type.Type).Select(x => x.Value); var types = properties .Where(x => !x.IsHidden() && !(x.PropertyType.GetListElementType() ?? x.PropertyType).IsSystemType() && !x.PropertyType.IsEnum && !x.IsAutoBound()) .Select(x => new TypeContext(x.PropertyType.GetListElementType() ?? x.PropertyType, parent: type)) .DistinctBy(x => x.Type, x => x.Chain) .ToList(); return(types.Concat(types .Where(x => type.Traverse(y => y.Parent).All(y => y.Type != x.Type)) .SelectMany(GetTypes)) .DistinctBy(x => x.Type, x => x.Chain) .ToList()); }
public IEnumerable <IValidationRule> DetermineRulesFor(Type type) { if (!type.CanBeCastTo <DomainEntity>()) { return(new IValidationRule[0]); } return(_descriptors.GetPropertiesFor(type).Values .Where(x => x.HasAttribute <UniqueAttribute>()) .Select(p => new { Prop = p, Key = p.GetAttribute <UniqueAttribute>().Key }) .GroupBy(x => x.Key) .Select(x => new UniqueValidationRule(x.Key, type, _transactionProcessor, x.Select(o => o.Prop)))); }
private IEnumerable <Parameter> createParameters(ActionCall call) { if (!call.HasInput) { return(new Parameter[0]); } var route = call.ParentChain().Route; var inputType = call.InputType(); IEnumerable <PropertyInfo> properties = _typeCache.GetPropertiesFor(inputType).Values; return(properties.Select(propertyInfo => createParameter(propertyInfo, route))); }
private void BuildComplexType( DataType dataType, Type type, bool inputGraph, IEnumerable <Type> ancestors, ActionCall action) { dataType.IsComplex = true; dataType.Members = (type.IsProjection() ? type.GetProjectionProperties() : _typeCache.GetPropertiesFor(type).Select(x => x.Value)) .Where(x => (!_configuration.ExcludeAutoBoundProperties || !x.IsAutoBound()) && !x.IsQuerystring(action) && !x.IsUrlParameter(action)) .Select(x => new { Property = x, Ancestors = ancestors.Concat(type), Type = x.PropertyType, UnwrappedType = x.PropertyType.UnwrapType(), Description = _memberConvention.GetDescription(x) }) .Where(x => x.Ancestors.All(y => y != x.UnwrappedType) && !x.Description.Hidden) .Select(x => _configuration.MemberOverrides.Apply(x.Property, new Member { Name = x.Description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = x.Description.WhenNotNull(y => y.Comments).OtherwiseDefault(), DefaultValue = inputGraph ? x.Description.WhenNotNull(y => y.DefaultValue) .WhenNotNull(z => z.ToSampleValueString(_configuration)).OtherwiseDefault() : null, SampleValue = x.Description.WhenNotNull(y => y.SampleValue) .WhenNotNull(z => z.ToSampleValueString(_configuration)).OtherwiseDefault(), Required = inputGraph && !x.Type.IsNullable() && x.Description.WhenNotNull(y => !y.Optional).OtherwiseDefault(), Optional = inputGraph && (x.Type.IsNullable() || x.Description.WhenNotNull(y => y.Optional).OtherwiseDefault()), Deprecated = x.Description.Deprecated, DeprecationMessage = x.Description.DeprecationMessage, Type = BuildGraph(dataType, x.Type, inputGraph, x.Ancestors, x.Description) })).ToList(); }
public ObjectBlock BlockFor(object input, BlockWritingContext context, string objectName = null) { Accessor implicitAccessor = null; var type = input.GetType(); if (context.Accessor != null) { var parentSettings = _blocks.SettingsFor(context.Accessor.OwnerType); implicitAccessor = parentSettings.FindImplicitValue(type); } var implicitValue = implicitAccessor != null ? implicitAccessor.GetValue(input).ToString() : null; var properties = _cache.GetPropertiesFor(type).Values; var settings = _blocks.SettingsFor(type); return(new ObjectBlock { Blocks = properties .Where(x => !settings.ShouldIgnore(input, new SingleProperty(x))) .Where(x => x.GetValue(input, null) != null && !isImplicitValue(x, implicitAccessor)) .Select(x => { context.StartProperty(x); var writer = _writerLibrary.WriterFor(context); var block = writer.Write(context); context.FinishProperty(); return block; }).ToList(), Name = _blocks.NameFor(new BlockToken(objectName)), ImplicitValue = implicitValue }); }