Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
		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);
		}
Exemplo n.º 7
0
        public object GetValue(DataReference value)
        {
            var childValue = parentValueAccessor.GetValue(value);

            return(childValueAccessor.GetValue(new DataReference(childValue)));
        }