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


C# Common.AddType方法代码示例

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


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

示例1: ValidateType

 public static void ValidateType(Type managedType, Common.Web.MVC.RestRpc.RestEndPoint endPoint)
 {
     return;
     
     if (managedType == typeof(void))
     {
         throw new Common.Web.MVC.RestRpc.RestException("Void is not a supported type.");
     }
     if (managedType.IsEnum)
     {
         managedType = Enum.GetUnderlyingType(managedType);
     }
     if (managedType.IsArray)
     {
         managedType = managedType.GetElementType();
     }
     if (((managedType != typeof(object)) && (managedType != typeof(string))) && ((managedType != typeof(DateTime)) && !managedType.IsPrimitive))
     {
         string str = "'" + managedType.FullName + "'";
         if (managedType.IsAbstract)
         {
             throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because it is abstract.");
         }
         if (managedType.IsInterface)
         {
             throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because it is an interface.");
         }
         if (managedType.IsNotPublic)
         {
             throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because it is not a public type.");
         }
         if (managedType.IsPointer)
         {
             throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because it is a pointer type.");
         }
         if (managedType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) == null)
         {
             throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because it does not have a public parameterless constructor.");
         }
         if (typeof(IDictionary).IsAssignableFrom(managedType))
         {
             if (managedType.IsGenericType)
             {
                 Type[] genericArguments = managedType.GetGenericArguments();
                 if (genericArguments[0] != typeof(string))
                 {
                     throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because the dictionary key is not a string type.");
                 }
                 try
                 {
                     endPoint.AddType(genericArguments[1]);
                 }
                 catch
                 {
                     throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because the dictionary value type is not supported.");
                 }
             }
         }
         /*
         else if (typeof(IList).IsAssignableFrom(managedType))
         {
             if (managedType.IsGenericType)
             {
                 try
                 {
                     Type[] typeArray2 = managedType.GetGenericArguments();
                     endPoint.AddType(typeArray2[0]);
                 }
                 catch
                 {
                     throw new Common.Web.MVC.RestRpc.RestException(str + " is not a supported type because the list item type is not supported.");
                 }
             }
         }
          */ 
         else
         {
             BindingFlags bindingAttr = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance;
             foreach (FieldInfo info2 in managedType.GetFields(bindingAttr))
             {
                 endPoint.AddType(info2.FieldType);
             }
             foreach (PropertyInfo info3 in managedType.GetProperties(bindingAttr))
             {
                 if ((info3.GetGetMethod() != null) && (info3.GetSetMethod() != null))
                 {
                     endPoint.AddType(info3.PropertyType);
                 }
             }
         }
     }
 }
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:92,代码来源:RestType.cs


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