private void ResolveArgument(GraphArgumentInfo argument, IResolutionContext resolutionContext)
 {
     if (argument.IsInjected)
     {
         object obj;
         var    argumentType = (TypeInfo)argument.Type.AttributeProvider;
         if (argumentType.AsType() == typeof(IResolutionContext) ||
             argumentType.ImplementedInterfaces.Any(iface => iface == typeof(IResolutionContext)))
         {
             obj = resolutionContext;
         }
         else if (argumentType.AsType() == typeof(IUserContext) ||
                  argumentType.ImplementedInterfaces.Any(iface => iface == typeof(IUserContext)))
         {
             obj = resolutionContext.UserContext;
         }
         else if (argumentType.AsType() == typeof(CancellationToken))
         {
             obj = resolutionContext.CancellationToken;
         }
         else
         {
             obj = resolutionContext.DependencyInjector?.Resolve(argumentType);
         }
         resolutionContext.SetArgument(argument.Name, obj);
     }
     else
     {
         var argumentValue = resolutionContext.GetArgument(argument);
         resolutionContext.SetArgument(argument.Name, Wrapper.Wrap(argument, argument.Type, argumentValue, true));
     }
 }
 private QueryArgument DeriveArgument(GraphArgumentInfo argumentInfo)
 {
     return(new QueryArgument(GetType(argumentInfo.Type))
     {
         Name = argumentInfo.Name,
         Description = argumentInfo.Description,
         DefaultValue = argumentInfo.DefaultValue,
     });
 }
Esempio n. 3
0
 public object GetArgument(GraphArgumentInfo argument)
 {
     var value = GetArgument(argument.Name, argument.DefaultValue);
     if (!argument.Type.IsNullable && value == null)
     {
         throw new ArgumentException($"Null value provided for non-nullable argument '{argument.Name}'.");
     }
     return value;
 }
Esempio n. 4
0
        private GraphArgumentInfo DeriveArgument(ParameterInfo parameterInfo)
        {
            var parameterType     = parameterInfo.ParameterType;
            var parameterTypeInfo = parameterType.GetTypeInfo();
            var argument          = new GraphArgumentInfo(_typeResolver, parameterInfo);

            if (_metaDataHandler.HasAttribute <InjectAttribute>(parameterInfo))
            {
                argument.Type       = GetType(parameterTypeInfo, true);
                argument.IsInjected = true;
            }
            else if (parameterType == typeof(object))
            {
                argument.Type       = GetType(parameterTypeInfo, true);
                argument.IsInjected = true;
            }
            else if (parameterTypeInfo.GetInterfaces().Any(iface => iface == typeof(IUserContext)))
            {
                argument.Type       = GetType(parameterTypeInfo, true);
                argument.IsInjected = true;
            }
            else if (parameterType == typeof(IResolutionContext))
            {
                argument.Type       = GetType(parameterTypeInfo, true);
                argument.IsInjected = true;
            }
            else if (parameterType == typeof(CancellationToken))
            {
                argument.Type       = GetType(parameterTypeInfo, true);
                argument.IsInjected = true;
            }
            else
            {
                argument.Type = GetType(parameterTypeInfo);
            }

            if (parameterInfo.HasDefaultValue)
            {
                var baseType = argument.Type.TypeRepresentation.BaseType();
                if (baseType.IsEnum && parameterInfo.DefaultValue != null)
                {
                    argument.DefaultValue = Enum.ToObject(baseType.AsType(), parameterInfo.DefaultValue);
                }
                else
                {
                    argument.DefaultValue = parameterInfo.DefaultValue;
                }
            }

            _metaDataHandler.DeriveMetaData(argument, parameterInfo);
            return(argument);
        }
Esempio n. 5
0
 public void MapArgument(GraphArgumentInfo entity, ParameterInfo parameterInfo)
 {
     HasMappedArgument = true;
 }
Esempio n. 6
0
 public override void MapArgument(GraphArgumentInfo argumentInfo, ParameterInfo parameterInfo)
 {
     argumentInfo.IsInjected = true;
     argumentInfo.Type.IsIgnored = true;
 }
Esempio n. 7
0
 public static void AndNotFlaggedAsInjected(this GraphArgumentInfo entity)
 {
     entity.IsInjected.ShouldEqual(false);
 }
Esempio n. 8
0
 public override void MapArgument(GraphArgumentInfo argumentInfo, ParameterInfo parameterInfo)
 {
     argumentInfo.Name = _nameNormalizer.AsArgumentName(parameterInfo.Name);
 }
Esempio n. 9
0
 public virtual void MapArgument(GraphArgumentInfo entity, ParameterInfo parameterInfo)
 {
 }