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


C# TypeNode.IsAssignableTo方法代码示例

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


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

示例1: HandlersMatching

    /// <summary>
    /// Returns a list of CfgBlock that are handlers of the current block, handling an exception
    /// of the given type, or a subtype thereof.
    /// </summary>
    /// <param name="exception">Type of exception thrown. It is assumed that any actual subtype could be thrown</param>
    /// <returns>All handlers that could apply directly to this exception.
    ///  In addition, if the method might not handle it, then the ExceptionExit block is
    /// part of this list.</returns>
    public System.Collections.IEnumerable/*CfgBlock*/ HandlersMatching(TypeNode exception) {
      ArrayList handlers = new ArrayList();

      CfgBlock currentBlock = this;

      while (currentBlock != null) {
        CfgBlock handler = this.cfg.ExceptionHandler(currentBlock);

        if (handler == null || handler.Statements == null || handler.Statements.Count < 1) break;

        Catch stat = handler.Statements[0] as Catch;

        if (stat != null) {
          if (exception.IsAssignableTo(stat.Type)) {
            // handles exceptions completely
            handlers.Add(handler);
            break;
          }
          if (stat.Type.IsAssignableTo(exception)) {
            // handles part of it
            handlers.Add(handler);
          }
          currentBlock = handler;
        }
        else {
          // must be the Unwind block
          handlers.Add(handler);
          break;
        }
      }
      return handlers;
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:40,代码来源:ControlFlow.cs

示例2: IsSubclassOf

        private static bool IsSubclassOf(TypeNode t1, TypeNode t2)
        {
            Contract.Requires(t1 != null);

            if (t2 == null) return false;

            return t1.IsAssignableTo(t2);
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:8,代码来源:HelperMethods.cs

示例3: FindImplementedMethod

        private static Method FindImplementedMethod(MethodList candidates, TypeNode targetTypeInstance)
        {
            if (candidates != null)
            {
                for (int i = 0; i < candidates.Count; i++)
                {
                    var candidate = candidates[i];
                    if (candidate == null) continue;

                    if (targetTypeInstance.IsAssignableTo(candidate.DeclaringType)) return candidate;
                }
            }

            return null;
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:15,代码来源:HelperMethods.cs

示例4: LeastCommonAncestor

		public static TypeNode LeastCommonAncestor(TypeNode t1, TypeNode t2) 
		{
			if (t1.IsAssignableTo(t2)) 
			{
				return t2;
			}

			// walk up t1 until assignable to t2
			TypeNode frame = t1;
			while (frame != null) 
			{
				if (t2.IsAssignableTo(frame))
				{
					return frame;
				}

				frame = frame.BaseType;
			}

			// if we get here, we haven't found a common basetype. Return object

			return Cci.SystemTypes.Object;
		}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:23,代码来源:CciUtils.cs

示例5: TypeMatches

   public bool TypeMatches(TypeNode t) {
     if (types == null || t == null) return true;
     foreach (TypeNode a in types) {
       if (a == null) return true;
       if (t.IsAssignableTo(a)) return true;
     }
     return false;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:8,代码来源:Validation.cs

示例6: IsValidTemplateArgument

        /// <summary>
        /// This is used to see if a type and parameter are valid template arguments
        /// </summary>
        /// <param name="type">The type to check</param>
        /// <param name="parameter">The parameter to check</param>
        /// <returns>True if it is valid, false if not</returns>
        private static bool IsValidTemplateArgument(TypeNode type, TypeNode parameter)
        {
            if(type == null)
                throw new ArgumentNullException("type");

            // Check that the parameter really is a type parameter
            ITypeParameter itp = parameter as ITypeParameter;

            if(itp == null)
                throw new ArgumentException("The 'parameter' argument is null or not an 'ITypeParameter'.");

            // Test constraints
            bool reference = ((itp.TypeParameterFlags & TypeParameterFlags.ReferenceTypeConstraint) > 0);

            if(reference && type.IsValueType)
                return (false);

            bool value = ((itp.TypeParameterFlags & TypeParameterFlags.ValueTypeConstraint) > 0);

            if(value && !type.IsValueType)
                return (false);

            InterfaceList contracts = parameter.Interfaces;

            if(contracts != null)
                foreach(Interface contract in contracts)
                    if(!type.IsAssignableTo(contract))
                        return false;

            TypeNode parent = parameter.BaseType;

            if(parent != null && !type.IsAssignableTo(parent))
                return false;

            // Okay, passed all tests
            return true;
        }
开发者ID:julianhaslinger,项目名称:SHFB,代码行数:43,代码来源:ExtensionMethodAddIn.cs


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