public ValueAccessor(InputParam @param) { this.Param = @param; }
public ValueAccessorChain(InputParam modelParam, Scope scope, ValuePath valuePath) { Boolean empty = (valuePath.Fragments.Length == 0); if (empty) { IsBroken = true; return; } List <ValueAccessor> accessors = new List <ValueAccessor>(); Int32 fragIndex = 0; ValuePathFragment frag = valuePath.Fragments[fragIndex]; LocalBuilder local = scope.ResolveLocal(frag.Literal); if (local != null) { accessors.Add(new ValueAccessor(local)); fragIndex++; } else { EachScope eachScope = (EachScope)scope.GetClosestScope(CompilerScopeType.Each, true); if (eachScope != null) { accessors.Add(new ValueAccessor(eachScope.LocThis)); } else { accessors.Add(new ValueAccessor(modelParam)); } } for (; fragIndex < valuePath.Fragments.Length && !IsBroken; fragIndex++) { frag = valuePath.Fragments[fragIndex]; ValueAccessor lastAccessor = accessors.Last(); switch (frag.Type) { case ValuePathFragmentType.Name: MemberInfo member = lastAccessor.ResultType.GetMember(frag.Literal, MemberTypes.Property | MemberTypes.Field, BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(); if (member != null) { accessors.Add(new ValueAccessor(member)); } else { IsBroken = true; } break; case ValuePathFragmentType.StringIndexer: PropertyInfo strIndexer = lastAccessor.ResultType.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new[] { typeof(String) }, null); if (strIndexer != null) { accessors.Add(new ValueAccessor(strIndexer, frag.Literal, strIndexer.PropertyType)); } else { IsBroken = true; } break; case ValuePathFragmentType.IntegerIndexer: if (lastAccessor.ResultType.IsArray) { accessors.Add(new ValueAccessor(null, Int32.Parse(frag.Literal), lastAccessor.ResultType.GetElementType())); } else { PropertyInfo intIndexer = lastAccessor.ResultType.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new[] { typeof(Int32) }, null); if (intIndexer != null) { accessors.Add(new ValueAccessor(intIndexer, Int32.Parse(frag.Literal), intIndexer.PropertyType)); } else { IsBroken = true; } } break; } } this.Accessors = accessors.ToArray(); }