当前位置: 首页>>代码示例>>C#>>正文


C# Routing.RespondWithNoContent方法代码示例

本文整理汇总了C#中Routing.RespondWithNoContent方法的典型用法代码示例。如果您正苦于以下问题:C# Routing.RespondWithNoContent方法的具体用法?C# Routing.RespondWithNoContent怎么用?C# Routing.RespondWithNoContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Routing的用法示例。


在下文中一共展示了Routing.RespondWithNoContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Map

        public void Map(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
        {
            container.ThrowIfNull("container");
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");

            route.RespondWithNoContent();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:9,代码来源:NoContentMapper.cs

示例2: MapAsync

        public Task MapAsync(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
        {
            container.ThrowIfNull("container");
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");

            route.RespondWithNoContent();

            return Task.Factory.Empty();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:11,代码来源:NoContentMapper.cs

示例3: Map

        public void Map(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
        {
            container.ThrowIfNull("container");
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");

            if (method.ReturnType == typeof(void))
            {
                route.RespondWithNoContent();
                return;
            }
            if (!method.ReturnType.ImplementsInterface<IResponse>())
            {
                throw new ApplicationException(String.Format("The return type of '{0}.{1}' does not implement '{2}'.", type.FullName, method.Name, typeof(IResponse).Name));
            }

            route.RespondWith(
                request =>
                    {
                        object instance;

                        try
                        {
                            instance = container().GetInstance(type);
                        }
                        catch (Exception exception)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type '{0}'.", type.FullName), exception);
                        }
                        if (instance == null)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type '{0}'.", type.FullName));
                        }

                        var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers);
                        IEnumerable<object> parameterValues = parameterValueRetriever.GetParameterValues(request, type, method);

                        return (IResponse)method.Invoke(instance, parameterValues.ToArray());
                    },
                method.ReturnType);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:42,代码来源:ResponseMethodReturnTypeMapper.cs

示例4: MapAsync


//.........这里部分代码省略.........
                        }
                        catch (Exception exception)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName), exception);
                        }
                        if (instance == null)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName));
                        }

                        var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers);
                        object[] parameterValues = (await parameterValueRetriever.GetParameterValuesAsync(context, type, method)).ToArray();
                        var mappedDelegateContexts = new List<IMappedDelegateContext>();

                        try
                        {
                            mappedDelegateContexts.AddRange(_contextFactories.Select(arg => arg.CreateContext(context, type, method)).Where(arg => arg != null));

                            IResponse response = await @delegate(instance, parameterValues);

                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Complete();
                            }

                            return response;
                        }
                        finally
                        {
                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Dispose();
                            }
                        }
                    },
                    methodGenericArgumentType);
            }
            else if (methodReturnTypeIsVoid)
            {
                ParameterInfo[] parameterInfos = method.GetParameters();
                ParameterExpression instanceParameterExpression = Expression.Parameter(typeof(object), "instance");
                ParameterExpression parametersParameterExpression = Expression.Parameter(typeof(object[]), "parameters");
                MethodCallExpression methodCallExpression =
                    Expression.Call(
                        Expression.Convert(instanceParameterExpression, type),
                        method,
                        parameterInfos.Select((arg, index) => Expression.Convert(
                            Expression.ArrayIndex(parametersParameterExpression, Expression.Constant(index)),
                            arg.ParameterType)));
                Action<object, object[]> @delegate = Expression.Lambda<Action<object, object[]>>(methodCallExpression, instanceParameterExpression, parametersParameterExpression).Compile();

                route.RespondWithNoContent(
                    async context =>
                    {
                        object instance;

                        try
                        {
                            instance = container().GetInstance(type);
                        }
                        catch (Exception exception)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName), exception);
                        }
                        if (instance == null)
                        {
                            throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName));
                        }

                        var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers);
                        object[] parameterValues = (await parameterValueRetriever.GetParameterValuesAsync(context, type, method)).ToArray();
                        var mappedDelegateContexts = new List<IMappedDelegateContext>();

                        try
                        {
                            mappedDelegateContexts.AddRange(_contextFactories.Select(arg => arg.CreateContext(context, type, method)).Where(arg => arg != null));

                            @delegate(instance, parameterValues);

                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Complete();
                            }
                        }
                        finally
                        {
                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Dispose();
                            }
                        }
                    });
            }
            else
            {
                throw new ApplicationException(String.Format("The return type of {0}.{1} must implement {2} or be a {3} whose generic type argument implements {2}.", type.FullName, method.Name, typeof(IResponse).Name, typeof(Task<>)));
            }

            return Task.Factory.Empty();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:101,代码来源:ResponseMethodReturnTypeMapper.cs


注:本文中的Routing.RespondWithNoContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。