當前位置: 首頁>>代碼示例>>C#>>正文


C# Method.GetParameterTypes方法代碼示例

本文整理匯總了C#中System.Compiler.Method.GetParameterTypes方法的典型用法代碼示例。如果您正苦於以下問題:C# Method.GetParameterTypes方法的具體用法?C# Method.GetParameterTypes怎麽用?C# Method.GetParameterTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Compiler.Method的用法示例。


在下文中一共展示了Method.GetParameterTypes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: VisitCall

    protected override object VisitCall(Variable dest, Variable receiver, Method callee, ExpressionList arguments, bool virtcall, Statement stat, object arg) {
      NonNullState nn=(NonNullState)arg;

      bool resultIsNonNull = false;

      // Check for Receiver
      if (!callee.IsStatic)
        CheckReceiver(stat,receiver,nn);


      // Check for parameter matching.
      if (arguments!=null && callee.Parameters != null){
        for(int i=0;i<callee.Parameters.Count;i++){
          Variable actual = (Variable)arguments[i];
          if (ts.IsNonNullType(callee.GetParameterTypes()[i])) {
            if(nn.IsNull(actual)) {
              HandleError(stat, actual, Error.CannotCoerceNullToNonNullType);
            }
            else if(!nn.IsNonNull(actual)) {
              //System.Console.WriteLine("visit call, argument: {0}", actual);
              HandleError(stat, actual, Error.CoercionToNonNullTypeMightFail, callee.GetParameterTypes()[i]);
            }
          }
          nn.HavocIndirect(actual, callee.Parameters[i].Type as Reference);
        }
      }

      // special case some methods
      if (this.IsAssertionMethodThatDoesNotReturn(callee)) {
        // we assume that all assertion methods are called with false.
        return null;
      }
      else if (this.NNChecker.IsAssertNotNullImplicitMethod(callee)) {
        if (arguments.Count == 1){
          Variable source = (Variable)arguments[0]; // guaranteed by CodeFlattener
          // compiler inserts this test throughout, so let's warn here.
          if (nn.IsNonNull(source)) {
            // opportunity to optimize away check.
            RecordUnnecessaryCheck(stat);
            // Console.WriteLine("Could optimize IsNonNull check at line {0}", stat.SourceContext.StartLine);
          }
          else {
            RecordNecessaryCheck(stat);
            if (nn.IsNull(source)) {
              HandleError(stat, source, Error.CannotCoerceNullToNonNullType);
              // do not explore this path further, except for exceptional path
              PushNullException(nn);
              return null;
            }
            else {
              //System.Console.WriteLine("visit call and callee is assertnotnullimplicitmethod");
              HandleError(stat, source, Error.CoercionToNonNullTypeMightFail, 
                OptionalModifier.For(SystemTypes.NonNullType, source.Type));
            }
          }
          nn = PushNullException(nn);
          nn.AssumeNonNull(source);
        }
      }
      else if (NNChecker.IsAssertNotNullMethod(callee)) {
        if (arguments.Count == 1){
          Variable source = (Variable)arguments[0]; // guaranteed by CodeFlattener
          // User inserted cast, so let's warn if it is unnecessary.
          if (nn.IsNonNull(source)) {
            // Let user know his check is useless here.
            RecordUnnecessaryCheck(stat);
            // Console.WriteLine("Could optimize IsNonNull check at line {0}", stat.SourceContext.StartLine);
          }
          else {
            RecordNecessaryCheck(stat);
            if (nn.IsNull(source)) {
              // Error already emitted at checker time. HandleError(stat, source, Error.CannotCoerceNullToNonNullType);
              // do not explore this path further except for exceptional path
              PushNullException(nn);
              return null;
            }
          }

          nn = PushNullException(nn);
          nn.AssumeNonNull(source);
        }
      }
      else if ( callee.Name.Name == "GetEnumerator" ) {
        // special case assume result is non-null because it is in generated code and confuses.
        if (dest != null) {
          nn.AssignNonNull(dest);
          dest = null; // avoid setting dest again below.
        }
      }
      else if (callee == GetTypeFromHandleMethod) {
        // special case that should be handled by annotating mscorlib
        if (dest != null) {
          nn.AssignNonNull(dest);
          dest = null; // avoid setting dest again below
        }
      }
      else {
        Property pget = IsPropertyGetter(callee);
        if (pget != null) {
          resultIsNonNull = nn.LoadProperty(receiver, pget, dest);
//.........這裏部分代碼省略.........
開發者ID:dbremner,項目名稱:specsharp,代碼行數:101,代碼來源:NonNullAnalysis.cs


注:本文中的System.Compiler.Method.GetParameterTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。