Пример #1
0
 protected virtual TypeBuilder CreateTypeBuilder(IEndPointMethodConfigurationReadOnly methodConfiguration,
                                                 TypeCreationContext creationContext)
 {
     return(_moduleBuilder.DefineType("DeserializeType" + _proxyCount, TypeAttributes.Public));
 }
        public MethodEndPointDelegate CreateParameterBindingMethod(IEndPointMethodConfigurationReadOnly configuration, Type parametersType)
        {
            var methodExpression = CreateMethodExpression(configuration, parametersType);

            return(methodExpression.Compile());
        }
Пример #3
0
 protected virtual void GenerateBooleanDefault(TypeBuilder typeBuilder, IEndPointMethodConfigurationReadOnly methodConfiguration, TypeCreationContext creationContext, ILGenerator ilGenerator, RpcParameterInfo rpcParameterInfo, FieldBuilder backingField)
 {
     ilGenerator.Emit(OpCodes.Ldarg_0);
     ilGenerator.EmitBoolean((bool)rpcParameterInfo.DefaultValue);
     ilGenerator.Emit(OpCodes.Stfld, backingField);
 }
Пример #4
0
        protected virtual IReadOnlyList <RpcParameterInfo> GenerateOrderedNonBodyParameterList(IEndPointMethodConfigurationReadOnly configuration)
        {
            AssignBindAction(configuration.Parameters);

            if (configuration.Parameters.All(parameter => parameter.ParameterSource != EndPointMethodParameterSource.PathParameter))
            {
                return(configuration.Parameters);
            }

            var newList = new List <RpcParameterInfo>();

            foreach (var routeInformationToken in configuration.RouteInformation.Tokens)
            {
                var rpcParameter = configuration.Parameters.First(parameter =>
                                                                  string.Compare(routeInformationToken.Name, parameter.Name,
                                                                                 StringComparison.CurrentCultureIgnoreCase) == 0);

                rpcParameter.TokenStopCharacter = routeInformationToken.StopCharacter;

                newList.Add(rpcParameter);
            }

            foreach (var configurationParameter in configuration.Parameters)
            {
                if (newList.Contains(configurationParameter))
                {
                    continue;
                }

                if (configurationParameter.ParameterSource != EndPointMethodParameterSource.PostBody &&
                    configurationParameter.ParameterSource != EndPointMethodParameterSource.PostParameter)
                {
                    newList.Add(configurationParameter);
                }
            }

            if (newList.Count == 0)
            {
                return(Array.Empty <RpcParameterInfo>());
            }

            return(newList.Equals(configuration.Parameters) ? configuration.Parameters : newList);
        }
Пример #5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="redirectPath"></param>
 /// <param name="configuration"></param>
 /// <param name="services"></param>
 public RedirectEndPointHandler(string redirectPath, IEndPointMethodConfigurationReadOnly configuration, EndPointServices services)
 {
     _redirectPath = redirectPath;
     Configuration = configuration;
     Services      = services;
 }
Пример #6
0
        /// <inheritdoc />
        public IEnumerable <Func <RequestExecutionContext, IRequestFilter> > ProvideFilters(ICurrentApiInformation currentApi, IEndPointMethodConfigurationReadOnly configurationReadOnly)
        {
            if (Shared)
            {
                var instance =
                    (IRequestFilter)ActivatorUtilities.CreateInstance(currentApi.ServiceProvider, _filterType);

                yield return(context => instance);
            }
            else
            {
                yield return(context =>
                             (IRequestFilter)ActivatorUtilities.CreateInstance(context.HttpContext.RequestServices,
                                                                               _filterType));
            }
        }
 protected virtual MethodEndPointDelegate CreateNoBodyParameterBinding(IEndPointMethodConfigurationReadOnly configuration, Type parametersType)
 {
     return(_noBodyParameterBinder.CreateParameterBindingMethod(configuration, parametersType));
 }
 private MethodEndPointDelegate CreateBodyParameterBinding(IEndPointMethodConfigurationReadOnly configuration, Type parametersType)
 {
     return(_bodyParameterBinder.CreateParameterBindingMethod(configuration, parametersType));
 }
        protected virtual MethodEndPointDelegate CreateDefaultBodyBinding(IEndPointMethodConfigurationReadOnly configuration, Type parametersType)
        {
            var closedMethod = _defaultBodyDeserialize.MakeGenericMethod(parametersType);

            return((MethodEndPointDelegate)closedMethod.CreateDelegate(typeof(MethodEndPointDelegate), this));
        }
Пример #10
0
        /// <inheritdoc />
        public IEnumerable <Func <RequestExecutionContext, IRequestFilter> > ProvideFilters(ICurrentApiInformation currentApi,
                                                                                            IEndPointMethodConfigurationReadOnly configurationReadOnly)
        {
            var viewName = GetViewName(currentApi, configurationReadOnly);

            var executor = ActivatorUtilities.CreateInstance <ViewExecutor>(currentApi.ServiceProvider);

            var modelMetadataProvider = currentApi.ServiceProvider.GetService(typeof(IModelMetadataProvider)) as IModelMetadataProvider;

            var tempDataProvider =
                currentApi.ServiceProvider.GetService(typeof(ITempDataProvider)) as ITempDataProvider;


            var filter = new ViewFilter(viewName, !IsPartial, executor, modelMetadataProvider, tempDataProvider, ContentType);

            return(new Func <RequestExecutionContext, IRequestFilter>[] { context => filter });
        }
Пример #11
0
 public HeadEndPointMethodHandler(IEndPointMethodHandler getMethodHandler, IEndPointMethodConfigurationReadOnly configuration)
 {
     _getMethodHandler = getMethodHandler;
     Configuration     = configuration;
 }
Пример #12
0
 public bool ShouldCompressResult(IEndPointMethodConfigurationReadOnly configuration)
 {
     return(!configuration.ReturnType.IsValueType);
 }
Пример #13
0
 /// <inheritdoc />
 public void AttributeMethodProperty(PropertyBuilder propertyBuilder, IEndPointMethodConfigurationReadOnly methodConfiguration,
                                     RpcParameterInfo parameterInfoParameter)
 {
 }
Пример #14
0
 /// <inheritdoc />
 public void AttributeMethodType(TypeBuilder typeBuilder, IEndPointMethodConfigurationReadOnly methodConfiguration)
 {
     typeBuilder.SetCustomAttribute(
         new CustomAttributeBuilder(_xmlTypeAttributeConstructorInfo, new object[] { "args" }));
 }
Пример #15
0
        protected virtual void ImplementRequestParametersInterface(TypeBuilder typeBuilder, IEndPointMethodConfigurationReadOnly methodConfiguration, TypeCreationContext creationContext)
        {
            GenerateTryGetParameter(typeBuilder, methodConfiguration, creationContext);

            GenerateTrySetParameter(typeBuilder, methodConfiguration, creationContext);

            GenerateParameterNames(typeBuilder, methodConfiguration, creationContext);

            GenerateArrayAccess(typeBuilder, methodConfiguration, creationContext);

            GenerateNumberOfParameters(typeBuilder, methodConfiguration, creationContext);
        }
        protected virtual MethodEndPointDelegate EmptyParameterBinding(IEndPointMethodConfigurationReadOnly configuration, out Type parametersType)
        {
            parametersType = typeof(EmptyParameters);

            return(_emptyParameterDelegate);
        }
Пример #17
0
        protected virtual void GenerateArrayAccess(TypeBuilder typeBuilder, IEndPointMethodConfigurationReadOnly methodConfiguration, TypeCreationContext creationContext)
        {
            GenerateGetItemMethod(typeBuilder, methodConfiguration, creationContext);

            GenerateSetItemMethod(typeBuilder, methodConfiguration, creationContext);
        }
        /// <summary>
        /// Wrap result expression
        /// </summary>
        /// <param name="endPointMethodConfiguration"></param>
        /// <param name="invokeMethod"></param>
        /// <param name="methodBodyStatements"></param>
        /// <param name="requestParameter"></param>
        /// <param name="invokeExpression"></param>
        protected virtual void WrapExpression <T>(IEndPointMethodConfigurationReadOnly endPointMethodConfiguration,
                                                  MethodInfo invokeMethod,
                                                  List <Expression> methodBodyStatements,
                                                  ParameterExpression requestParameter,
                                                  Expression invokeExpression)
        {
            if (invokeMethod.ReturnType == typeof(void))
            {
                var closedMethod = _taskFromResult.MakeGenericMethod(typeof(object));

                methodBodyStatements.Add(invokeExpression);

                var callFromResult = Expression.Call(closedMethod, Expression.Constant(null, typeof(object)));

                methodBodyStatements.Add(callFromResult);
            }
            else if (invokeMethod.ReturnType == typeof(Task))
            {
                var taskExpression = Expression.Call(_wrapTask, invokeExpression);

                methodBodyStatements.Add(taskExpression);
            }
            else if (invokeMethod.ReturnType == typeof(ValueTask))
            {
                var valueTaskExpression = Expression.Call(_wrapValueTask, invokeExpression);

                methodBodyStatements.Add(valueTaskExpression);
            }
            else if (invokeMethod.ReturnType.IsConstructedGenericType)
            {
                var openType = invokeMethod.ReturnType.GetGenericTypeDefinition();

                if (openType == typeof(ValueTask <>))
                {
                    if (endPointMethodConfiguration.WrappedType != null)
                    {
                        var closedMethod = _wrapResultValueTaskAsync.MakeGenericMethod(endPointMethodConfiguration.WrappedType, invokeMethod.ReturnType.GenericTypeArguments[0]);

                        var callExpression = Expression.Call(closedMethod, invokeExpression);

                        methodBodyStatements.Add(callExpression);
                    }
                    else
                    {
                        var asTaskMethod = invokeMethod.ReturnType.GetMethod("AsTask");

                        var callExpression = Expression.Call(invokeExpression, asTaskMethod);

                        methodBodyStatements.Add(callExpression);
                    }
                }
                else if (openType == typeof(Task <>))
                {
                    if (endPointMethodConfiguration.WrappedType != null)
                    {
                        var closedMethod = _wrapResultTaskAsync.MakeGenericMethod(endPointMethodConfiguration.WrappedType, invokeMethod.ReturnType.GenericTypeArguments[0]);

                        var callExpression = Expression.Call(closedMethod, invokeExpression);

                        methodBodyStatements.Add(callExpression);
                    }
                    else
                    {
                        methodBodyStatements.Add(invokeExpression);
                    }
                }
                else
                {
                    var closedMethod = _taskFromResult.MakeGenericMethod(typeof(T));

                    var callFromResult = Expression.Call(closedMethod, invokeExpression);

                    methodBodyStatements.Add(callFromResult);
                }
            }
            else
            {
                if (endPointMethodConfiguration.WrappedType != null)
                {
                    var closedMethod = _wrapResult.MakeGenericMethod(endPointMethodConfiguration.WrappedType, invokeMethod.ReturnType);

                    var wrapExpression = Expression.Call(closedMethod, invokeExpression);

                    methodBodyStatements.Add(wrapExpression);
                }
                else
                {
                    var closedMethod = _taskFromResult.MakeGenericMethod(typeof(T));

                    var callFromResult = Expression.Call(closedMethod, invokeExpression);

                    methodBodyStatements.Add(callFromResult);
                }
            }
        }