本文整理汇总了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);
}
}
}
}
}