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


C# SyntaxTree.GetChanges方法代码示例

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


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

示例1: Compare

        /// <summary>
        /// Generates Diff results for each change that occurred from the ancestor to the changed
        /// </summary>
        /// <param name="ancestor">
        /// The abstract syntax tree that the changed version originated from
        /// </param>
        /// <param name="changed">The abstract syntax tree that resulted from changing the ancestor</param>
        /// <returns>Changes between the ancestor and changed</returns>
        public static IEnumerable<Diff> Compare(SyntaxTree ancestor, SyntaxTree changed)
        {
            var offset = 0; //Tracks differences in indexes moving through the changed syntax tree
            foreach (var change in changed.GetChanges(ancestor))
            { //Assumes that this list is sorted by place in file
                var origLength = change.Span.Length;
                var offsetChange = (change.NewText.Length - origLength);

                var chanStart = change.Span.Start + offset;
                var chanLength = origLength + offsetChange;

                offset += offsetChange;

                var d = new Diff
                {
                    Ancestor = SpanDetails.Create(change.Span, ancestor),
                    Changed = SpanDetails.Create(new TextSpan(chanStart, chanLength), changed)
                };

                yield return d;
            }
        }
开发者ID:semdiffdotnet,项目名称:semdiff,代码行数:30,代码来源:Diff.cs

示例2: TryGetChangesIgnoringWhiteSpace

    private static bool TryGetChangesIgnoringWhiteSpace(SyntaxTree oldTree, SyntaxTree newTree, out IEnumerable<string> textchanges) 
    {
      #region CodeContracts
      Contract.Requires(oldTree != null);
      Contract.Requires(newTree != null);
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn<IEnumerable<string>>(out textchanges) != null);
      #endregion CodeContracts

      var workspace = MSBuildWorkspace.Create();
      oldTree = Formatter.Format(oldTree.GetRoot(), workspace).SyntaxTree;
      newTree = Formatter.Format(newTree.GetRoot(), workspace).SyntaxTree;
      textchanges = null;
      if (oldTree == newTree) 
      {
        return false;
      }
      var changes = newTree.GetChanges(oldTree);
      if (!changes.Any()) {
        return false;
      }
      textchanges = changes.Select(x => x.NewText.Trim());
      //textchanges = changes.Select(x => x.NewText.Trim());
      if (textchanges.All(x => x == ""))
      {
        return false;
      }
      return true;

    }
开发者ID:scottcarr,项目名称:ccbot,代码行数:29,代码来源:Writer.cs


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