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


C# TypeNode.Clone方法代码示例

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


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

示例1: VisitTypeNode

    public virtual Differences VisitTypeNode(TypeNode typeNode1, TypeNode typeNode2){
      Differences differences = this.GetMemberDifferences(typeNode1, typeNode2);
      if (differences == null){Debug.Assert(false); differences = new Differences(typeNode1, typeNode2);}
      if (differences.NumberOfDifferences > 0 || differences.NumberOfSimilarities > 0) return differences;
      if (typeNode1 == null || typeNode2 == null){
        if (typeNode1 != typeNode2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      TypeNode changes = (TypeNode)typeNode2.Clone();
      TypeNode deletions = (TypeNode)typeNode2.Clone();
      TypeNode insertions = (TypeNode)typeNode2.Clone();

      //Short circuit comparison if assembly qualified full name of typeNode1 is not the same as that of typeNode2
      string tName1 = typeNode1.FullName;
      string tName2 = typeNode2.FullName;
      if (string.CompareOrdinal(tName1, tName2) != 0){
        differences.NumberOfDifferences++;
        goto done;
      }
      if (typeNode1.DeclaringModule != this.OriginalModule || typeNode2.DeclaringModule != this.NewModule){
        differences.NumberOfDifferences++;
        goto done;
      }

      AttributeList attrChanges, attrDeletions, attrInsertions;
      Differences diff = this.VisitAttributeList(typeNode1.Attributes, typeNode2.Attributes, out attrChanges, out attrDeletions, out attrInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Attributes = attrChanges;
      deletions.Attributes = attrDeletions;
      insertions.Attributes = attrInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitTypeNode(typeNode1.BaseType, typeNode2.BaseType);
      if (diff == null){Debug.Assert(false); return differences;}
      //BaseType is read only. Class overrides this method and updates changes, deletions and insertions
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (typeNode1.ClassSize == typeNode2.ClassSize) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      diff = this.VisitTypeNode(typeNode1.DeclaringType, typeNode2.DeclaringType);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.DeclaringType = diff.Changes as TypeNode;
      deletions.DeclaringType = diff.Deletions as TypeNode;
      insertions.DeclaringType = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.DeclaringType && diff.Deletions == deletions.DeclaringType && diff.Insertions == insertions.DeclaringType);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (typeNode1.Flags == typeNode2.Flags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (typeNode1.HidesBaseClassMember == typeNode2.HidesBaseClassMember) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      InterfaceList ifaceChanges, ifaceDeletions, ifaceInsertions;
      diff = this.VisitInterfaceReferenceList(typeNode1.Interfaces, typeNode2.Interfaces, out ifaceChanges, out ifaceDeletions, out ifaceInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Interfaces = ifaceChanges;
      deletions.Interfaces = ifaceDeletions;
      insertions.Interfaces = ifaceInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (typeNode1.IsGeneric == typeNode2.IsGeneric) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      MemberList memChanges, memDeletions, memInsertions;
      diff = this.VisitMemberList(typeNode1.Members, typeNode2.Members, out memChanges, out memDeletions, out memInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Members = memChanges;
      deletions.Members = memDeletions;
      insertions.Members = memInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitIdentifier(typeNode1.Name, typeNode2.Name);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Name = diff.Changes as Identifier;
      deletions.Name = diff.Deletions as Identifier;
      insertions.Name = diff.Insertions as Identifier;
      Debug.Assert(diff.Changes == changes.Name && diff.Deletions == deletions.Name && diff.Insertions == insertions.Name);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitIdentifier(typeNode1.Namespace, typeNode2.Namespace);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Namespace = diff.Changes as Identifier;
      deletions.Namespace = diff.Deletions as Identifier;
      insertions.Namespace = diff.Insertions as Identifier;
      Debug.Assert(diff.Changes == changes.Namespace && diff.Deletions == deletions.Namespace && diff.Insertions == insertions.Namespace);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (typeNode1.NodeType == typeNode2.NodeType) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (typeNode1.PackingSize == typeNode2.PackingSize) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      SecurityAttributeList secChanges, secDeletions, secInsertions;
      diff = this.VisitSecurityAttributeList(typeNode1.SecurityAttributes, typeNode2.SecurityAttributes, out secChanges, out secDeletions, out secInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.SecurityAttributes = secChanges;
      deletions.SecurityAttributes = secDeletions;
      insertions.SecurityAttributes = secInsertions;
//.........这里部分代码省略.........
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:101,代码来源:Comparer.cs

示例2: CopyTypeParameter

 private TypeNode CopyTypeParameter(TypeNode typeParameter)
 {
     var fresh = (TypeNode)typeParameter.Clone();
     fresh.Interfaces = fresh.Interfaces.Clone();
     this.forwarding[typeParameter.UniqueKey] = fresh;
     return fresh;
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:7,代码来源:Specializer.cs

示例3: VisitTypeNode

        internal TypeNode VisitTypeNode(TypeNode type, Identifier mangledName, TypeNodeList templateArguments, TypeNode template, bool delayVisitToNestedTypes)
        {
            if (type == null) return null;
            TypeNode dup = (TypeNode)this.DuplicateFor[type.UniqueKey];
            if (dup != null) return dup;
            this.DuplicateFor[type.UniqueKey] = dup = (TypeNode)type.Clone();
            if (mangledName != null)
            {
                this.TargetModule.StructurallyEquivalentType[mangledName.UniqueIdKey] = dup;
                dup.TemplateArguments = templateArguments;
            }
            dup.arrayTypes = null;
            dup.constructors = null;
            dup.consolidatedTemplateArguments = null;
            dup.consolidatedTemplateParameters = null;
#if DEBUG && !MinimalReader
            dup.DebugLabel = null;
#endif
#if !NoXml
            dup.DocumentationId = null;
            if (this.CopyDocumentation) dup.Documentation = type.Documentation;
#endif
            dup.defaultMembers = null;
#if !MinimalReader
            dup.explicitCoercionFromTable = null;
            dup.explicitCoercionMethods = null;
            dup.implicitCoercionFromTable = null;
            dup.implicitCoercionMethods = null;
            dup.implicitCoercionToTable = null;
#endif
            dup.memberCount = 0;
            dup.memberTable = null;
            dup.modifierTable = null;
            dup.NestedTypes = null;
            dup.pointerType = null;
            dup.ProviderHandle = null;
            dup.ProvideTypeAttributes = null;
            dup.ProvideTypeMembers = null;
            dup.ProvideNestedTypes = null;
            dup.referenceType = null;
#if !NoReflection
            dup.runtimeType = null;
#endif
            dup.structurallyEquivalentMethod = null;
            TypeParameter tp = dup as TypeParameter;
            if (tp != null) tp.structuralElementTypes = null;
            ClassParameter cp = dup as ClassParameter;
            if (cp != null) cp.structuralElementTypes = null;
            dup.szArrayTypes = null;
            if (this.RecordOriginalAsTemplate) dup.Template = type;
            dup.TemplateArguments = null;
            dup.TemplateInstances = null;
            dup.DeclaringModule = this.TargetModule;
            dup.DeclaringType = this.TargetType;
            TypeNode savedTargetType = this.TargetType;
            this.TargetType = dup;
            dup.Attributes = this.VisitAttributeList(type.Attributes);
            dup.SecurityAttributes = this.VisitSecurityAttributeList(type.SecurityAttributes);
            Class c = dup as Class;
            if (c != null) c.BaseClass = (Class)this.VisitTypeReference(c.BaseClass);
            dup.Interfaces = this.VisitInterfaceReferenceList(dup.Interfaces);
            dup.TemplateParameters = this.VisitTypeReferenceList(type.TemplateParameters);
            dup.consolidatedTemplateParameters = null;
#if !MinimalReader
            if (dup is MethodScope)
                dup.members = this.VisitMemberList(type.members);
            else
#endif
                if (!this.RecordOriginalAsTemplate)
                {
                    if (!delayVisitToNestedTypes)
                        dup.nestedTypes = this.VisitNestedTypes(dup, type.NestedTypes);
                    dup.members = null;
                    dup.ProvideTypeMembers = new TypeNode.TypeMemberProvider(this.ProvideTypeMembers);
                    dup.ProviderHandle = type;
                }
                else
                {
                    dup.members = null;
                    dup.ProvideNestedTypes = new TypeNode.NestedTypeProvider(this.ProvideNestedTypes);
                    dup.ProvideTypeMembers = new TypeNode.TypeMemberProvider(this.ProvideTypeMembers);
                    dup.ProviderHandle = type;
                }
            DelegateNode delegateNode = dup as DelegateNode;
            if (delegateNode != null)
            {
#if !MinimalReader
                if (!delegateNode.IsNormalized || !this.RecordOriginalAsTemplate)
                {
                    if (!delegateNode.IsNormalized)
                        ((DelegateNode)type).ProvideMembers();
                    delegateNode.Parameters = this.VisitParameterList(delegateNode.Parameters);
                    delegateNode.ReturnType = this.VisitTypeReference(delegateNode.ReturnType);
                }
                else
#endif
                {
                    delegateNode.Parameters = null;
                    delegateNode.ReturnType = null;
                }
//.........这里部分代码省略.........
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:101,代码来源:Duplicator.cs

示例4: VisitTypeReference

        public override TypeNode VisitTypeReference(TypeNode type)
        {
            if (type == null) return null;
            TypeNode dup = (TypeNode)this.DuplicateFor[type.UniqueKey];
            if (dup != null && (dup.Template != type || this.RecordOriginalAsTemplate)) return dup;
            switch (type.NodeType)
            {
                case NodeType.ArrayType:
                    ArrayType arrType = (ArrayType)type;
                    TypeNode elemType = this.VisitTypeReference(arrType.ElementType);
                    if (elemType == arrType.ElementType) return arrType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    this.TypesToBeDuplicated[arrType.UniqueKey] = arrType;
                    dup = elemType.GetArrayType(arrType.Rank, arrType.Sizes, arrType.LowerBounds);
                    break;
                case NodeType.ClassParameter:
                case NodeType.TypeParameter:
                    if (this.RecordOriginalAsTemplate) return type;
                    if (this.TypesToBeDuplicated[type.UniqueKey] == null) return type;
                    dup = this.VisitTypeNode(type);
                    break;
#if !MinimalReader
                case NodeType.DelegateNode:
                    {
                        FunctionType ftype = type as FunctionType;
                        if (ftype == null) goto default;
                        dup = FunctionType.For(this.VisitTypeReference(ftype.ReturnType), this.VisitParameterList(ftype.Parameters), this.TargetType);
                        break;
                    }
#endif
                case NodeType.Pointer:
                    Pointer pType = (Pointer)type;
                    elemType = this.VisitTypeReference(pType.ElementType);
                    if (elemType == pType.ElementType) return pType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    dup = elemType.GetPointerType();
                    break;
                case NodeType.Reference:
                    Reference rType = (Reference)type;
                    elemType = this.VisitTypeReference(rType.ElementType);
                    if (elemType == rType.ElementType) return rType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    dup = elemType.GetReferenceType();
                    break;
#if ExtendedRuntime    
        case NodeType.TupleType:{
          TupleType tType = (TupleType)type;
          bool reconstruct = false;
          MemberList members = tType.Members;
          int n = members == null ? 0 : members.Count;
          FieldList fields = new FieldList(n);
          for (int i = 0; i < n; i++){
            //^ assert members != null;
            Field f = members[i] as Field;
            if (f == null) continue;
            f = (Field)f.Clone();
            fields.Add(f);
            TypeNode oft = f.Type;
            TypeNode ft = f.Type = this.VisitTypeReference(f.Type);
            if (ft != oft) reconstruct = true;
          }
          if (!reconstruct) return tType;
          dup = TupleType.For(fields, this.TargetType);
          break;}
        case NodeType.TypeIntersection:
          TypeIntersection tIntersect = (TypeIntersection)type;
          dup = TypeIntersection.For(this.VisitTypeReferenceList(tIntersect.Types), this.TargetType);
          break;
        case NodeType.TypeUnion:
          TypeUnion tUnion = (TypeUnion)type;
          TypeNodeList types = this.VisitTypeReferenceList(tUnion.Types);
          if (types == null) { Debug.Fail(""); return null; }
          if (this.TargetType == null)
            dup = TypeUnion.For(types, TargetModule);
          else
            dup = TypeUnion.For(types, this.TargetType);
          break;
#endif
#if !MinimalReader
                //These types typically have only one reference and do not have pointer identity. Just duplicate them.
                case NodeType.ArrayTypeExpression:
                    ArrayTypeExpression aExpr = (ArrayTypeExpression)type.Clone();
                    elemType = this.VisitTypeReference(aExpr.ElementType);
                    if (elemType == null) { Debug.Fail(""); return aExpr; }
                    aExpr.ElementType = elemType;
                    return aExpr;
                case NodeType.BoxedTypeExpression:
                    BoxedTypeExpression bExpr = (BoxedTypeExpression)type.Clone();
                    bExpr.ElementType = this.VisitTypeReference(bExpr.ElementType);
                    return bExpr;
                case NodeType.ClassExpression:
                    ClassExpression cExpr = (ClassExpression)type.Clone();
                    cExpr.Expression = this.VisitExpression(cExpr.Expression);
                    cExpr.TemplateArguments = this.VisitTypeReferenceList(cExpr.TemplateArguments);
                    return cExpr;
#endif
#if ExtendedRuntime
        case NodeType.ConstrainedType:
          ConstrainedType conType = (ConstrainedType)type;
          TypeNode underlyingType = this.VisitTypeReference(conType.UnderlyingType);
//.........这里部分代码省略.........
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:101,代码来源:Duplicator.cs

示例5: VisitTypeReference

    public override TypeNode VisitTypeReference(TypeNode type){
      if (type == null) return null;
      TypeNode dup = (TypeNode)this.DuplicateFor[type.UniqueKey];
      if (dup != null && (dup.Template != type || this.RecordOriginalAsTemplate)) return dup;
      if (this.RecordOriginalAsTemplate) {
          // [11/1/12 MAF: There was a bug that made it not possible to skip the copy here because generic methods have 
          // type parameters that needed to be duplicated including types instantiated with these type parameters, 
          // e.g.,  Task<T> Foo<T>().
          // Returning here had left Task<T> whereas the method has been changed to Task<T'>
          // Fixing this required not copying the generic method parameters when creating an instance, and instead copying
          // the template parameters during specializing. This fixed some bugs in the specializer too where we lost constraints
          // or mistakenly updated constraints of the generic type rather than the instance.
        return type; // mapping will be done by Specializer
      }
      switch (type.NodeType){
        case NodeType.ArrayType:
          ArrayType arrType = (ArrayType)type;
          TypeNode elemType = this.VisitTypeReference(arrType.ElementType);
          if (elemType == arrType.ElementType) return arrType;
          if (elemType == null) { Debug.Fail(""); return null; }
          //this.TypesToBeDuplicated[arrType.UniqueKey] = arrType;
          dup = elemType.GetArrayType(arrType.Rank, arrType.Sizes, arrType.LowerBounds);
          break;
        case NodeType.ClassParameter:
        case NodeType.TypeParameter:
          if (this.RecordOriginalAsTemplate) return type;
          if (this.TypesToBeDuplicated[type.UniqueKey] == null) return type;
          dup = this.VisitTypeNode(type);
          break;
#if !MinimalReader
        case NodeType.DelegateNode:{
          FunctionType ftype = type as FunctionType;
          if (ftype == null) goto default;
          dup = FunctionType.For(this.VisitTypeReference(ftype.ReturnType), this.VisitParameterList(ftype.Parameters), this.TargetType);
          break;}
#endif
        case NodeType.Pointer:
          Pointer pType = (Pointer)type;
          elemType = this.VisitTypeReference(pType.ElementType);
          if (elemType == pType.ElementType) return pType;
          if (elemType == null) { Debug.Fail(""); return null; }
          dup = elemType.GetPointerType();
          break;
        case NodeType.Reference:
          Reference rType = (Reference)type;
          elemType = this.VisitTypeReference(rType.ElementType);
          if (elemType == rType.ElementType) return rType;
          if (elemType == null) { Debug.Fail(""); return null; }
          dup = elemType.GetReferenceType();
          break;
#if ExtendedRuntime    
        case NodeType.TupleType:{
          TupleType tType = (TupleType)type;
          bool reconstruct = false;
          MemberList members = tType.Members;
          int n = members == null ? 0 : members.Count;
          FieldList fields = new FieldList(n);
          for (int i = 0; i < n; i++){
            //^ assert members != null;
            Field f = members[i] as Field;
            if (f == null) continue;
            f = (Field)f.Clone();
            fields.Add(f);
            TypeNode oft = f.Type;
            TypeNode ft = f.Type = this.VisitTypeReference(f.Type);
            if (ft != oft) reconstruct = true;
          }
          if (!reconstruct) return tType;
          dup = TupleType.For(fields, this.TargetType);
          break;}
        case NodeType.TypeIntersection:
          TypeIntersection tIntersect = (TypeIntersection)type;
          dup = TypeIntersection.For(this.VisitTypeReferenceList(tIntersect.Types), this.TargetType);
          break;
        case NodeType.TypeUnion:
          TypeUnion tUnion = (TypeUnion)type;
          TypeNodeList types = this.VisitTypeReferenceList(tUnion.Types);
          if (types == null) { Debug.Fail(""); return null; }
          if (this.TargetType == null)
            dup = TypeUnion.For(types, TargetModule);
          else
            dup = TypeUnion.For(types, this.TargetType);
          break;
#endif
#if !MinimalReader
        //These types typically have only one reference and do not have pointer identity. Just duplicate them.
        case NodeType.ArrayTypeExpression:
          ArrayTypeExpression aExpr = (ArrayTypeExpression)type.Clone();
          elemType = this.VisitTypeReference(aExpr.ElementType);
          if (elemType == null) { Debug.Fail(""); return aExpr; }
          aExpr.ElementType = elemType;
          return aExpr;
        case NodeType.BoxedTypeExpression:
          BoxedTypeExpression bExpr = (BoxedTypeExpression)type.Clone();
          bExpr.ElementType = this.VisitTypeReference(bExpr.ElementType);
          return bExpr;
        case NodeType.ClassExpression:
          ClassExpression cExpr = (ClassExpression)type.Clone();
          cExpr.Expression = this.VisitExpression(cExpr.Expression);
          cExpr.TemplateArguments = this.VisitTypeReferenceList(cExpr.TemplateArguments);
//.........这里部分代码省略.........
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:Duplicator.cs


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