本文整理汇总了C#中Type.IsInterface方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsInterface方法的具体用法?C# Type.IsInterface怎么用?C# Type.IsInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.IsInterface方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelfAndBaseTypes
static IEnumerable<Type> SelfAndBaseTypes(Type type)
{
if (type.IsInterface())
{
List<Type> types = new List<Type>();
AddInterface(types, type);
return types;
}
return SelfAndBaseClasses(type);
}
示例2: GenerateConversion
static Expression GenerateConversion(Expression expr, Type type, int errorPos)
{
Type exprType = expr.Type;
if (exprType == type)
return expr;
if (exprType.IsValueType() && type.IsValueType())
{
if ((IsNullableType(exprType) || IsNullableType(type)) &&
GetNonNullableType(exprType) == GetNonNullableType(type))
return Expression.Convert(expr, type);
if ((IsNumericType(exprType) || IsEnumType(exprType)) &&
(IsNumericType(type)) || IsEnumType(type))
return Expression.ConvertChecked(expr, type);
}
if (exprType.IsAssignableFrom(type) || type.IsAssignableFrom(exprType) || exprType.IsInterface() || type.IsInterface())
return Expression.Convert(expr, type);
// Try to Parse the string rather that just generate the convert statement
if (expr.NodeType == ExpressionType.Constant && exprType == typeof(string))
{
string text = (string)((ConstantExpression)expr).Value;
// DateTime is parsed as UTC time.
DateTime dateTime;
if (type == typeof(DateTime) && DateTime.TryParse(text, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
return Expression.Constant(dateTime, type);
object[] arguments = { text, null };
#if DNXCORE50
MethodInfo method = type.GetMethod("TryParse", new [] { typeof(string), type.MakeByRefType() });
#else
MethodInfo method = type.GetMethod("TryParse", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string), type.MakeByRefType() }, null);
#endif
if (method != null && (bool)method.Invoke(null, arguments))
return Expression.Constant(arguments[1], type);
}
throw ParseError(errorPos, Res.CannotConvertValue, GetTypeName(exprType), GetTypeName(type));
}
示例3: FindGenericType
static Type FindGenericType(Type generic, Type type)
{
while (type != null && type != typeof(object))
{
if (type.IsGenericType() && type.GetGenericTypeDefinition() == generic)
return type;
if (generic.IsInterface())
{
foreach (Type intfType in type.GetInterfaces())
{
Type found = FindGenericType(generic, intfType);
if (found != null) return found;
}
}
type = type.BaseType();
}
return null;
}
示例4: GenerateConversion
static Expression GenerateConversion(Expression expr, Type type, int errorPos)
{
Type exprType = expr.Type;
if (exprType == type)
return expr;
if (exprType.IsValueType() && type.IsValueType())
{
if ((IsNullableType(exprType) || IsNullableType(type)) &&
GetNonNullableType(exprType) == GetNonNullableType(type))
return Expression.Convert(expr, type);
if ((IsNumericType(exprType) || IsEnumType(exprType)) &&
(IsNumericType(type)) || IsEnumType(type))
return Expression.ConvertChecked(expr, type);
}
if (exprType.IsAssignableFrom(type) || type.IsAssignableFrom(exprType) || exprType.IsInterface() || type.IsInterface())
return Expression.Convert(expr, type);
throw ParseError(errorPos, Res.CannotConvertValue, GetTypeName(exprType), GetTypeName(type));
}