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


C# TypeInfo.isAssignableFrom方法代码示例

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


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

示例1: getImplicitConversion

 public static TypeInfo getImplicitConversion(TypeInfo fromType, TypeInfo toType) {
     if (toType.IsClosed && toType.isAssignableFrom(fromType)) {
         return fromType;
     }
     if (toType.OriginalTypeDefinition == fromType.OriginalTypeDefinition) {
         var it1 = toType.GenericArguments.iterator();
         var it2 = fromType.GenericArguments.iterator();
         while (it1.hasNext()) {
             var t1 = it1.next();
             var t2 = it2.next();
             switch (t1.TypeKind) {
             case GenericParameter:
             case UnboundedWildcard:
             case LowerBoundedWildcard:
                 break;
             case UpperBoundedWildcard:
                 if (!hasImplicitConversion(t2, t1.WildcardBound)) {
                     return null;
                 }
                 break;
             default:
                 if (!hasImplicitConversion(t2, t1)) {
                     return null;
                 }
                 break;
             }
         }
         return fromType;
     }
     foreach (var it in fromType.Interfaces) {
         var t = getImplicitConversion(it, toType);
         if (t != null) {
             return t;
         }
     }
     if (fromType.BaseType == null) {
         return null;
     }
     return getImplicitConversion(fromType.BaseType, toType);
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:40,代码来源:BytecodeHelper.stab.cs

示例2: isAssignable

 static bool isAssignable(CompilerContext context, TypeInfo type, ExpressionNode expression) {
     var info = expression.getUserData(typeof(ExpressionInfo));
     if (info == null) {
         return !type.IsPrimitive;
     }
     var right = getType(context, expression);
     if (type.isAssignableFrom(right)) {
         return true;
     }
     if (expression.ExpressionKind == ExpressionKind.ArrayInitializer) {
         if (!type.IsArray) {
             return false;
         }
         foreach (var e in ((ArrayInitializerExpressionNode)expression).Values) {
             if (!isAssignable(context, type.ElementType, e)) {
                 return false;
             }
         }
         return true;
     }
     if (type.IsNumeric && info.IsConstant) {
         switch (type.NumericTypeKind) {
         case Byte: {
             long value;
             switch (right.TypeKind) {
             case Char:
                 value = ((Character)info.Value).charValue();
                 break;
             case Int:
             case Long:
             case Short:
                 value = ((Number)info.Value).longValue();
                 break;
             default:
                 return false;
             }
             return Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE;
         }
         case Char: {
             long value;
             switch (right.TypeKind) {
             case Byte:
             case Int:
             case Long:
             case Short:
                 value = ((Number)info.Value).longValue();
                 break;
             default:
                 return false;
             }
             return Character.MIN_VALUE <= value && value <= Character.MAX_VALUE;
         }
         case Short: {
             long value;
             switch (right.TypeKind) {
             case Byte:
                 return true;
             case Char:
                 value = ((Character)info.Value).charValue();
                 break;
             case Int:
             case Long:
                 value = ((Number)info.Value).longValue();
                 break;
             default:
                 return false;
             }
             return Short.MIN_VALUE <= value && value <= Short.MAX_VALUE;
         }
         case Int: {
             long value;
             switch (right.getTypeKind()) {
             case Char:
                 value = ((Character)info.Value).charValue();
                 break;
             case Byte:
             case Short:
                 return true;
             case Long:
                 value = ((Number)info.getValue()).longValue();
                 break;
             default:
                 return false;
             }
             return Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE;
         }
         }
     }
     return false;
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:90,代码来源:ValidationHelper.stab.cs

示例3: getBetterConversionFromType

 private BetterConversionResult getBetterConversionFromType(TypeInfo leftType, TypeInfo rightType, TypeInfo fromType) {
     if (leftType == rightType) {
         return BetterConversionResult.Neither;
     }
     if (fromType == leftType) {
         return BetterConversionResult.LeftIsBetter;
     }
     if (fromType == rightType) {
         return BetterConversionResult.RightIsBetter;
     }
     if (!leftType.isAssignableFrom(rightType) && rightType.isAssignableFrom(leftType)) {
         return BetterConversionResult.LeftIsBetter;
     }
     if (!rightType.isAssignableFrom(leftType) && leftType.isAssignableFrom(rightType)) {
         return BetterConversionResult.RightIsBetter;
     }
     return BetterConversionResult.Neither;
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:18,代码来源:MethodResolver.stab.cs


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