public static IXor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription> FromPath(IReadOnlyList <string> path, Type accessingType, Type valueType) { var firstPropName = path.First(); var rest = path.Skip(1); if (!rest.Any()) { var firstPropDesc = new PropertyDescription(accessingType, valueType, firstPropName); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(firstPropDesc)); } else { var firstPropDesc = new PropertyDescription(accessingType, TypeOf.Property(firstPropName, accessingType), firstPropName); var firstFromRest = rest.First(); var restOfNodes = rest.SelectWithHistory ( oxStart: xStr => new PropertyDescription(firstPropDesc.ValueType, TypeOf.Property(firstFromRest, firstPropDesc.ValueType), firstFromRest), oxOnLast: (xStr, xPrevNode) => new PropertyDescription(xPrevNode.ValueType, valueType, xStr), oxNext: (xStr, xPrevNode) => new PropertyDescription(xPrevNode.ValueType, TypeOf.Property(xStr, xPrevNode.ValueType), xStr) ) .ToList(); var chain = new PropertyDescriptionChain(firstPropDesc, restOfNodes); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(chain)); } }
private static IXor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription> _ExtendXor(IXor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription> _this, IReadOnlyList <IPropertyDescription> otherNodes) { if (_this.IsA) { var singleProp = _this.A; var chain = new PropertyDescriptionChain(singleProp, otherNodes); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(chain)); } else { var chain = _this.B; var others = chain.Nodes.Skip(1).Concat(otherNodes).ToList(); var chainExpanded = new PropertyDescriptionChain(chain.FirstNode, others); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(chainExpanded)); } }
private static IXor2 <IPropertyDescription <TOwner, TValue>, IPropertyDescriptionChain <TOwner, TValue>, IPropertyOrChainDescription> _DescriptionFromExpression <TOwner, TValue>(IReadOnlyList <MemberExpression> expressions) where TOwner : class { var rest = expressions.Skip(1).ToList(); if (!rest.Any()) { var single = new PropertyDescription <TOwner, TValue>(expressions.First().Member.Name); return(new Xor2 <IPropertyDescription <TOwner, TValue>, IPropertyDescriptionChain <TOwner, TValue>, IPropertyOrChainDescription>(single)); } var firstExpression = expressions.First(); var first = new PropertyDescription <TOwner>(firstExpression.Type, firstExpression.Member.Name); var linkedDescriptions = _LinkDescriptionsRec(first, rest).ToList(); var chain = new PropertyDescriptionChain <TOwner, TValue>(first, linkedDescriptions); return(new Xor2 <IPropertyDescription <TOwner, TValue>, IPropertyDescriptionChain <TOwner, TValue>, IPropertyOrChainDescription>(chain)); }
static public IXor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription> Add <TOwner, TIntermediateValue, TFinalValue>(this IXor2 <IPropertyDescription <TOwner, TIntermediateValue>, IPropertyDescriptionChain <TOwner, TIntermediateValue>, IPropertyOrChainDescription> _this, IXor2 <IPropertyDescription <TIntermediateValue, TFinalValue>, IPropertyDescriptionChain <TIntermediateValue, TFinalValue>, IPropertyOrChainDescription> other) where TOwner : class where TIntermediateValue : class { if (_this.IsA) { var singleProp = _this.A; var chain = new PropertyDescriptionChain <TOwner, TFinalValue>(singleProp, other.Common.Nodes); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(chain)); } else { var chain = _this.B; var others = chain.Nodes.Skip(1).Concat(other.Common.Nodes).ToList(); var chainExpanded = new PropertyDescriptionChain(chain.FirstNode, others); return(new Xor2 <IPropertyDescription, IPropertyDescriptionChain, IPropertyOrChainDescription>(chainExpanded)); } }