public static T Select <TObject, T>(IValueAccessor <TObject> value, DataReference dataReference, Func <TObject, DataReference, T> selector) where TObject : GraphQLObject { Check.IsNotNull(value, nameof(value)); Check.IsNotNull(selector, nameof(selector)); var childReference = new DataReference(value.GetValue(dataReference)); return(selector(value.GraphQLType, childReference)); }
private static Action <IInvocation> GetValueAccessorGet(PropertyInfo property, IValueAccessor accessor) { return((invocation) => invocation.ReturnValue = accessor.GetValue( new ValueAccessorContext { Instance = invocation.InvocationTarget as IInterceptableType, Property = property, BackingPropertyGetter = () => { invocation.Proceed(); return invocation.ReturnValue; }, BackingPropertySetter = (value) => { throw new NotSupportedException("Setting property not supported while getting"); }, }, property.Name)); }
private static IEnumerable <T> Select <TObject, T>(IValueAccessor value, DataReference dataReference, Func <TObject, DataReference, T> selector, TObject tObject) where TObject : GraphQLObject { if (value.GetValue(dataReference) is IEnumerable enumerable) { return(enumerable .OfType <object>() .Select(x => selector(tObject, new DataReference(x))) .ToList()); } throw new Exception("not an enumerable"); }
public TMonad GetValue(IContext <TMonad> ctx) { var overrideContext = ctx as OverrideContext <TMonad>; if (overrideContext.Overrides.TryGetValue(propName, out var v)) { return(v); } if (baseAccessor == null && overrideContext.BaseContext.TryGetAccessor(propName, out var accessor)) { baseAccessor = accessor; } return(baseAccessor == null ? ctx.Monad.Unit : baseAccessor.GetValue(overrideContext.BaseContext)); }
public TMonad Evaluate(IContext <TMonad> context) { var cType = context.GetType(); if (cType == lastType) { return(lastAccessor.GetValue(context)); } if (!accessors.TryGetValue(cType, out var accessor)) { if (!context.TryGetAccessor(Name, out accessor)) { accessor = new UnitAccessor <TMonad>(Monad); } accessors[cType] = accessor; } lastType = cType; lastAccessor = accessor; return(accessor.GetValue(context)); }
private static Action<IInvocation> GetValueAccessorGet(PropertyInfo property, IValueAccessor accessor) { return (invocation) => invocation.ReturnValue = accessor.GetValue( new ValueAccessorContext { Instance = invocation.InvocationTarget as IInterceptableType, Property = property, BackingPropertyGetter = () => { invocation.Proceed(); return invocation.ReturnValue; }, BackingPropertySetter = (value) => { throw new NotSupportedException("Setting property not supported while getting"); }, }, property.Name); }
public object GetValue(DataReference value) { var childValue = parentValueAccessor.GetValue(value); return(childValueAccessor.GetValue(new DataReference(childValue))); }