Ejemplo n.º 1
0
        private HttpRequestConvertFormDataHanlder GetConvertFormDataHanlder()
        {
            var formDataType = FormData.GetType();
            var key          = new HttpConvertDataHanlderKey(formDataType, ContentType);
            HttpRequestConvertFormDataHanlder hanlder = null;

            if (_convertFormDataHanlders.ContainsKey(key))
            {
                hanlder = _convertFormDataHanlders[key];
            }
            if (hanlder == null)
            {
                var closestAncestor = formDataType.FindClosestAncestor(_convertFormDataHanlders.Where(t => ContentType.Contains(t.Key.ContentType, StringComparison.OrdinalIgnoreCase)).Select(t => t.Key.Type));
                if (closestAncestor != null)
                {
                    key     = new HttpConvertDataHanlderKey(closestAncestor, ContentType);
                    hanlder = _convertFormDataHanlders[key];
                }
            }
            if (hanlder == null)
            {
                throw new Exception($"未注册ContentType为{ContentType},DataType为{formDataType.FullName}的序列化Hanlder");
            }
            return(hanlder);
        }
Ejemplo n.º 2
0
 public static void RegiserConvertFormDataHanlder(Type[] types, string[] contentTypes, HttpRequestConvertFormDataHanlder hanlder)
 {
     foreach (var type in types)
     {
         foreach (var ct in contentTypes)
         {
             var key = new HttpConvertDataHanlderKey(type, ct);
             if (_convertFormDataHanlders.ContainsKey(key))
             {
                 _convertFormDataHanlders[key] = hanlder;
             }
             else
             {
                 _convertFormDataHanlders.Add(key, hanlder);
             }
         }
     }
 }