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


C# ParameterList.Clone方法代码示例

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


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

示例1: VisitParameterList

 public virtual Differences VisitParameterList(ParameterList list1, ParameterList list2,
   out ParameterList changes, out ParameterList deletions, out ParameterList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new ParameterList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   //Compare definitions that have matching key attributes
   TrivialHashtable matchingPosFor = new TrivialHashtable();
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     Parameter nd2 = list2[j];
     if (nd2 == null || nd2.Name == null) continue;
     matchingPosFor[nd2.Name.UniqueIdKey] = j;
     insertions.Add(null);
   }
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Parameter nd1 = list1[i];
     if (nd1 == null || nd1.Name == null) continue;
     object pos = matchingPosFor[nd1.Name.UniqueIdKey];
     if (!(pos is int)) continue;
     //^ assert pos != null;
     int j = (int)pos;
     //^ assume list2 != null; //since there was entry int matchingPosFor
     Parameter nd2 = list2[j];
     //^ assume nd2 != null;
     //nd1 and nd2 have the same key attributes and are therefore treated as the same entity
     matchedNodes[nd1.UniqueKey] = nd1;
     matchedNodes[nd2.UniqueKey] = nd2;
     //nd1 and nd2 may still be different, though, so find out how different
     Differences diff = this.VisitParameter(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.NumberOfDifferences != 0){
       changes[i] = diff.Changes as Parameter;
       deletions[i] = diff.Deletions as Parameter;
       insertions[i] = diff.Insertions as Parameter;
       insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
       Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
       differences.NumberOfDifferences += diff.NumberOfDifferences;
       differences.NumberOfSimilarities += diff.NumberOfSimilarities;
       continue;
     }
     changes[i] = null;
     deletions[i] = null;
     insertions[i] = null;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Parameter nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     Parameter nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   return differences;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:76,代码来源:Comparer.cs

示例2: CoerceArguments

    public virtual void CoerceArguments(ParameterList parameters, ref ExpressionList arguments, bool doNotVisitArguments, CallingConventionFlags callingConvention) {
      if (arguments == null) arguments = new ExpressionList();
      int n = arguments.Count;
      int m = parameters == null ? 0 : parameters.Count;
      //if fewer arguments than parameters, supply default values
      for (; n < m; n++) {
        Parameter p = parameters[n];
        TypeNode type = p == null ? null : p.Type;
        if (type == null) type = SystemTypes.Object;
        type = TypeNode.StripModifiers(type);
        if (p.DefaultValue != null)
          arguments.Add(p.DefaultValue);
        else {
          //There should already have been a complaint. Just recover.
          TypeNode elementType = parameters[n].GetParamArrayElementType();
          if (elementType != null) break;
          arguments.Add(new UnaryExpression(new Literal(type, SystemTypes.Type), NodeType.DefaultValue, type));
        }
      }
      if (m > 0) {
        TypeNode elementType = TypeNode.StripModifiers(parameters[m-1].GetParamArrayElementType());
        TypeNode lastArgType = null;
        if (elementType != null && (n > m || (n == m - 1) || n == m
          && (lastArgType = TypeNode.StripModifiers(arguments[m-1].Type)) != null && 
              !this.GetTypeView(lastArgType).IsAssignableTo(TypeNode.StripModifiers(parameters[m-1].Type)) &&
          !(arguments[m-1].Type == SystemTypes.Object && arguments[m-1] is Literal && ((Literal)arguments[m-1]).Value == null))) {
          ExpressionList varargs = new ExpressionList(n-m+1);
          for (int i = m-1; i < n; i++)
            varargs.Add(arguments[i]);
          Debug.Assert(m <= n || m == n+1);
          while (m > n++) arguments.Add(null);
          arguments[m-1] = new ConstructArray(parameters[m-1].GetParamArrayElementType(), varargs);
          arguments.Count = m;
          n = m;
        }
      }
      if (n > m) {
        // Handle Varargs
        Debug.Assert(n == m+1);
        Debug.Assert((callingConvention & CallingConventionFlags.VarArg) != 0);
        ArglistArgumentExpression ale = arguments[n-1] as ArglistArgumentExpression;
        if (ale != null) {
          // rewrite nested arguments to one level.
          // otherwise, the method does not match and I expect the Checker to issue a nice message.
          ExpressionList newArgs = new ExpressionList(n - 1 + ale.Operands.Count);
          for (int i=0; i<n-1; i++) {
            newArgs.Add(arguments[i]);
          }
          for (int i=0; i<ale.Operands.Count; i++) {
            newArgs.Add(ale.Operands[i]);
          }
          arguments = newArgs;
          // adjust formal parameters to actuals
          parameters = (ParameterList)parameters.Clone();
          for (int i=0; i<ale.Operands.Count; i++) {
            if (arguments[i+m] != null) {
              TypeNode pType = arguments[i+m].Type;
              Reference r = pType as Reference;
              if (r != null) pType = r.ElementType;
              parameters.Add(new Parameter(null, pType));
            } else {
              parameters.Add(new Parameter(null, SystemTypes.Object));
            }
          }
          m = arguments.Count;
          n = m;
        } else {
          // leave arguments and let type coercion fail
          // adjust formal parameters to actuals
          parameters = (ParameterList)parameters.Clone();
          parameters.Add(Resolver.ArglistDummyParameter);
          n = parameters.Count;
        }
      }
      if (doNotVisitArguments) {
        for (int i = 0; i < n; i++) {
          Parameter p = this.typeSystem.currentParameter = parameters[i];
          Literal lit = arguments[i] as Literal;
          if (lit != null && lit.Value is TypeNode && p.Type == SystemTypes.Type)
            arguments[i] = lit;
          else {
            if (!this.DoNotVisitArguments(p.DeclaringMethod)) {
              Expression e = arguments[i] = this.typeSystem.ImplicitCoercion(arguments[i], p.Type, this.TypeViewer);
              if (e is BinaryExpression && e.NodeType == NodeType.Box) e = arguments[i] = ((BinaryExpression)e).Operand1;
            }
          }
        }
      } else {
        for (int i = 0; i < n; i++) {

          Parameter p = this.typeSystem.currentParameter = parameters[i];

          bool savedMayReferenceThisAndBase = this.MayReferenceThisAndBase;
          if (p.IsOut
            && this.currentMethod is InstanceInitializer) {
            // allow calls "f(out this.x)" before the explicit base ctor call
            this.MayReferenceThisAndBase = true;
          }

          arguments[i] = this.CoerceArgument(this.VisitExpression(arguments[i]), p);
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:Checker.cs


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