• HttpRequestMessage扩展方法


    public static class HttpRequestMessageExtensions
        {
            /// <summary>
            /// Gets the <see cref="HttpConfiguration"/> for the given request.
            /// </summary>
            /// <param name="request">The HTTP request.</param>
            /// <returns>The <see cref="HttpConfiguration"/>.</returns>
            public static HttpConfiguration GetConfiguration(this HttpRequestMessage request)
            {
                if (request == null)
                {
                    throw new ArgumentException("request");
                }
    
                return request.GetProperty<HttpConfiguration>(HttpPropertyKeys.HttpConfigurationKey);
            }
    
            /// <summary>
            /// Gets the <see cref="System.Threading.SynchronizationContext"/> for the given request or null if not available.
            /// </summary>
            /// <param name="request">The HTTP request.</param>
            /// <returns>The <see cref="System.Threading.SynchronizationContext"/> or null.</returns>
            public static SynchronizationContext GetSynchronizationContext(this HttpRequestMessage request)
            {
                if (request == null)
                {
                    throw new ArgumentException("request");
                }
    
                return request.GetProperty<SynchronizationContext>(HttpPropertyKeys.SynchronizationContextKey);
            }
    
            /// <summary>
            /// Gets the <see cref="System.Web.Http.Routing.IHttpRouteData"/> for the given request or null if not available.
            /// </summary>
            /// <param name="request">The HTTP request.</param>
            /// <returns>The <see cref="System.Web.Http.Routing.IHttpRouteData"/> or null.</returns>
            public static IHttpRouteData GetRouteData(this HttpRequestMessage request)
            {
                if (request == null)
                {
                    throw new ArgumentException("request");
                }
    
                return request.GetProperty<IHttpRouteData>(HttpPropertyKeys.HttpRouteDataKey);
            }
    
            public static T GetProperty<T>(this HttpRequestMessage request, string key)
            {
                T value = default(T);
                object @object = null;
                request.Properties.TryGetValue(key, out @object);
                if (@object is T)
                {
                    value = (T)@object;
                }
                else
                {
                    throw new InvalidCastException(string.Format("无效类型转换:{0}", typeof(T).FullName));
                }
                return value;
            }
            
        }
  • 相关阅读:
    mysql 库,表,数据操作
    mysql 初识数据库
    MySQL 索引 视图 触发器 存储过程 函数
    MySQL 事物和数据库锁
    MySQL 约束和数据库设计
    MySQL 创建千万集数据
    MySQL 各种引擎
    求1,1,2,3,5,8,13 斐波那契数列第N个数的值
    WEB前端研发工程师编程能力成长之路(1)
    XML DOM
  • 原文地址:https://www.cnblogs.com/fanfan-90/p/12048909.html
Copyright © 2020-2023  润新知