本文整理汇总了C#中Mono.CSharp.TypeParameterSpec.IsConvertibleToInterface方法的典型用法代码示例。如果您正苦于以下问题:C# TypeParameterSpec.IsConvertibleToInterface方法的具体用法?C# TypeParameterSpec.IsConvertibleToInterface怎么用?C# TypeParameterSpec.IsConvertibleToInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.TypeParameterSpec
的用法示例。
在下文中一共展示了TypeParameterSpec.IsConvertibleToInterface方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImplicitTypeParameterConversion
public static Expression ImplicitTypeParameterConversion (Expression expr, TypeParameterSpec expr_type, TypeSpec target_type)
{
//
// From T to a type parameter U, provided T depends on U
//
if (target_type.IsGenericParameter) {
if (expr_type.TypeArguments != null) {
foreach (var targ in expr_type.TypeArguments) {
if (!TypeSpecComparer.Override.IsEqual (target_type, targ))
continue;
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType && !((TypeParameterSpec)target_type).IsReferenceType)
return new BoxedCast (expr, target_type);
return new ClassCast (expr, target_type);
}
}
return null;
}
//
// LAMESPEC: From T to dynamic type because it's like T to object
//
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
//
// From T to its effective base class C
// From T to any base class of C (it cannot contain dynamic or be of dynamic type)
// From T to any interface implemented by C
//
var base_type = expr_type.GetEffectiveBase ();
if (base_type == target_type || TypeSpec.IsBaseClass (base_type, target_type, false) || base_type.ImplementsInterface (target_type, true)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
return null;
}