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


C# Method.Clone方法代码示例

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


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

示例1: VisitMethod

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

      AttributeList attrChanges, attrDeletions, attrInsertions;
      Differences diff = this.VisitAttributeList(method1.Attributes, method2.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;

      if (!this.DoNotCompareBodies){
        diff = this.VisitBlock(method1.Body, method2.Body);
        if (diff == null){Debug.Assert(false); return differences;}
        changes.Body = diff.Changes as Block;
        deletions.Body = diff.Deletions as Block;
        insertions.Body = diff.Insertions as Block;
        Debug.Assert(diff.Changes == changes.Body && diff.Deletions == deletions.Body && diff.Insertions == insertions.Body);
        differences.NumberOfDifferences += diff.NumberOfDifferences;
        differences.NumberOfSimilarities += diff.NumberOfSimilarities;
      }

      if (method1.CallingConvention == method2.CallingConvention) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      diff = this.VisitMember(method1.DeclaringMember, method2.DeclaringMember);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.DeclaringMember = diff.Changes as Member;
      deletions.DeclaringMember = diff.Deletions as Member;
      insertions.DeclaringMember = diff.Insertions as Member;
      Debug.Assert(diff.Changes == changes.DeclaringMember && diff.Deletions == deletions.DeclaringMember && diff.Insertions == insertions.DeclaringMember);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (method1.Flags == method2.Flags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.HasCompilerGeneratedSignature == method2.HasCompilerGeneratedSignature) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.ImplFlags == method2.ImplFlags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.InitLocals == method2.InitLocals) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.IsGeneric == method2.IsGeneric) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      TypeNodeList typeChanges, typeDeletions, typeInsertions;
      diff = this.VisitTypeNodeList(method1.ImplementedTypes, method2.ImplementedTypes, out typeChanges, out typeDeletions, out typeInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.ImplementedTypes = typeChanges;
      deletions.ImplementedTypes = typeDeletions;
      insertions.ImplementedTypes = typeInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitIdentifier(method1.Name, method2.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;

      if (method1.NodeType == method2.NodeType) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      ParameterList parChanges, parDeletions, parInsertions;
      diff = this.VisitParameterList(method1.Parameters, method2.Parameters, out parChanges, out parDeletions, out parInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Parameters = parChanges;
      deletions.Parameters = parDeletions;
      insertions.Parameters = parInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (method1.PInvokeFlags == method2.PInvokeFlags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.PInvokeImportName == method2.PInvokeImportName) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      if (method1.PInvokeModule == method2.PInvokeModule ||
        (method1.PInvokeModule != null && method2.PInvokeModule != null && method1.PInvokeModule.Name == method2.PInvokeModule.Name))
        differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      diff = this.VisitAttributeList(method1.ReturnAttributes, method2.ReturnAttributes, out attrChanges, out attrDeletions, out attrInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.ReturnAttributes = attrChanges;
      deletions.ReturnAttributes = attrDeletions;
      insertions.ReturnAttributes = attrInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitTypeNode(method1.ReturnType, method2.ReturnType);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.ReturnType = diff.Changes as TypeNode;
      deletions.ReturnType = diff.Deletions as TypeNode;
      insertions.ReturnType = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.ReturnType && diff.Deletions == deletions.ReturnType && diff.Insertions == insertions.ReturnType);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;
//.........这里部分代码省略.........
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:101,代码来源:Comparer.cs

示例2: VisitMethod

        public override Method VisitMethod(Method method)
        {
            if (method == null) return null;
            Method dup = (Method)this.DuplicateFor[method.UniqueKey];
            if (dup != null) return dup;
            this.DuplicateFor[method.UniqueKey] = dup = (Method)method.Clone();
            dup.ProviderHandle = null;
            if (TargetPlatform.UseGenerics)
            {
                this.FindTypesToBeDuplicated(method.TemplateParameters);
            }
#if !FxCop
            dup.LocalList = null;
#endif
            Method savedTarget = this.TargetMethod;
            this.TargetMethod = dup;
            if (TargetPlatform.UseGenerics)
            {
                dup.TemplateParameters = this.VisitTypeParameterList(method.TemplateParameters);
            }
#if !MinimalReader
            if (dup.Scope != null)
            {
                this.TypesToBeDuplicated[dup.Scope.UniqueKey] = dup.Scope;
                dup.Scope = this.VisitTypeNode(dup.Scope) as MethodScope;
            }
#endif
            dup.DeclaringMember = this.VisitMemberReference(dup.DeclaringMember);
#if !NoXml
            if (this.CopyDocumentation) dup.Documentation = method.Documentation;
#endif
            dup.ImplementedInterfaceMethods = this.VisitMethodReferenceList(method.ImplementedInterfaceMethods);
            dup.DeclaringType = this.TargetType;
            if (!method.IsAbstract) dup.Body = this.DummyBody;
            if (this.RecordOriginalAsTemplate)
            {
                if (method.Template != null)
                    dup.Template = method.Template;
                else
                    dup.Template = method;
            }
            dup.PInvokeModule = this.VisitModuleReference(dup.PInvokeModule);
            if (method.ReturnTypeMarshallingInformation != null)
                dup.ReturnTypeMarshallingInformation = method.ReturnTypeMarshallingInformation.Clone();
            dup.ThisParameter = (This)this.VisitParameter(dup.ThisParameter);
            dup = base.VisitMethod(dup);
            //^ assume dup != null;
            dup.fullName = null;
#if !NoXml
            dup.DocumentationId = null;
#endif
            dup.ProviderHandle = method; // we always need the handle, as we may use it for attributes.
            dup.Attributes = null;
            dup.ProvideMethodAttributes = new Method.MethodAttributeProvider(this.ProvideMethodAttributes);
            if (!this.SkipBodies && !method.IsAbstract)
            {
                dup.Body = null;
                dup.ProvideBody = new Method.MethodBodyProvider(this.ProvideMethodBody);
            }
            if (this.SkipBodies) dup.Instructions = new InstructionList(0);

            this.TargetMethod = savedTarget;
            return dup;
        }
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:64,代码来源:Duplicator.cs

示例3: AddOptionalOverloads

 private static void AddOptionalOverloads(Class ce, Method me, List<Parameter> optionalParameters)
 {
     foreach (var prm in optionalParameters.ToArray())
     {
         var me2 = me.Clone();
         me2.Parameters.Remove(me2.Parameters.Where(t => t.Name == prm.Name).First());
         ce.Members.Add(me2);
         var op2 = optionalParameters.ToArray().ToList();
         op2.Remove(prm);
         AddOptionalOverloads(ce, me2, op2);
     }
 }
开发者ID:hultqvist,项目名称:SharpKit-SDK,代码行数:12,代码来源:TinyMCECodeGenerator.cs

示例4: VisitMethodInternal

    /// <summary>
    /// Does not copy the method's template parameters unless they are marked for duplication already.
    /// </summary>
    public Method VisitMethodInternal(Method method){
      if (method == null) return null;
      Method dup = (Method)this.DuplicateFor[method.UniqueKey];
      if (dup != null) return dup;
      this.DuplicateFor[method.UniqueKey] = dup = (Method)method.Clone();
      dup.ProviderHandle = null;
#if !FxCop
      dup.LocalList = null;
#endif
      Method savedTarget = this.TargetMethod;
      this.TargetMethod = dup;
      var savedTemplateParameters = method.TemplateParameters;
      if (TargetPlatform.UseGenerics
          && !this.RecordOriginalAsTemplate
          )
      {
          dup.TemplateParameters = this.VisitTypeParameterList(savedTemplateParameters);
          savedTemplateParameters = null;
      }
      else
      {
          dup.TemplateParameters = null; // avoid visiting them
      }

#if !MinimalReader && !CodeContracts
      if (dup.Scope != null) {
        this.TypesToBeDuplicated[dup.Scope.UniqueKey] = dup.Scope;
        dup.Scope = this.VisitTypeNode(dup.Scope) as MethodScope;
      }
#endif
#if !NoXml
      if (this.CopyDocumentation) dup.Documentation = method.Documentation;
#endif
      dup.OverriddenMember = null; // let instantiation be recomputed
      dup.ImplementedInterfaceMethods = this.VisitMethodReferenceList(method.ImplementedInterfaceMethods);
      dup.ImplicitlyImplementedInterfaceMethods = null; // just reset it so it gets recomputed if ever asked for
      dup.DeclaringType = this.TargetType;
      if (!method.IsAbstract) dup.Body = this.DummyBody;
      if (this.RecordOriginalAsTemplate) {
        if (method.Template != null)
          dup.Template = method.Template;
        else
          dup.Template = method;
      }
      dup.PInvokeModule = this.VisitModuleReference(dup.PInvokeModule);
      if (method.ReturnTypeMarshallingInformation != null)
        dup.ReturnTypeMarshallingInformation = method.ReturnTypeMarshallingInformation.Clone();
      dup.ThisParameter = (This)this.VisitParameter(dup.ThisParameter);
#if ExtendedRuntime || CodeContracts
      dup.ProvideContract = null;
      dup.contract = null;
#endif
      dup = base.VisitMethod(dup);
      //^ assume dup != null;

      // restore template parameters if we need to
      if (savedTemplateParameters != null)
      {
          dup.TemplateParameters = savedTemplateParameters.Clone();
          savedTemplateParameters = null;
      }
      // Visiting the declaring member can cause this method to be re-entered,
      // so only visit after we duplicated the other properties so that we 
      // do not return a half-duplicated method.

      // it doesn't make sense to copy a getter/setter/event method without the corresponding event
      // (one can always pre-populate if necessary)
      dup.DeclaringMember = (Member)this.Visit(dup.DeclaringMember);
      dup.fullName = null;
#if !NoXml
      dup.DocumentationId = null;
#endif
      dup.ProviderHandle = method; // we always need the handle, as we may use it for attributes.
      dup.Attributes = null;
      dup.ProvideMethodAttributes = new Method.MethodAttributeProvider(this.ProvideMethodAttributes);
#if ExtendedRuntime || CodeContracts
      dup.ProvideContract = new Method.MethodContractProvider(this.ProvideMethodContract);
#endif
      if (!this.SkipBodies && !method.IsAbstract)
      {
        dup.Body = null;
        dup.ProvideBody = new Method.MethodBodyProvider(this.ProvideMethodBody);
      }
      if (this.SkipBodies) dup.Instructions = new InstructionList(0);
      
      this.TargetMethod = savedTarget;
      return dup;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:91,代码来源:Duplicator.cs


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