Esempio n. 1
0
        /// <summary>
        /// walk the syntax trees and replace each field declaration like int x,y,z
        /// with int x; int y; int z;
        /// if one of those has a readonly suggestion
        /// </summary>
        /// <param name="compilation"></param>
        /// <param name="annotations"></param>
        /// <returns></returns>
        private static Compilation SpiltReadOnlyFieldDeclarations(Compilation compilation, IEnumerable <ReadonlyField> annotations)
        {
            #region CodeContracts
            Contract.Requires(compilation != null);
            Contract.Requires(annotations != null);
            Contract.Ensures(Contract.Result <Compilation>() != null);
            #endregion CodeContracts

            // this is probably terribly ineffiecient, but once you modify the syntaxTree in anyway you have to get a new semantic model
            foreach (var annotation in annotations)
            {
                var st      = compilation.SyntaxTrees.First(x => x.FilePath.Equals(annotation.FileName, StringComparison.OrdinalIgnoreCase));
                var fsr     = new FieldSplitterRewriter(annotation, st, compilation);
                var newroot = fsr.Visit(st.GetRoot()).SyntaxTree.GetRoot();
                compilation = compilation.ReplaceSyntaxTree(st, SyntaxFactory.SyntaxTree(newroot, null, st.FilePath));
            }
            //foreach (var annotationGroup in annotations.GroupBy(x => x.FileName))
            //{
            //  if (annotationGroup.Any())
            //  {
            //    var first = annotationGroup.First();
            //    RBLogger.Info("Splitting fields in {0}", first.FileName);
            //    var st = compilation.SyntaxTrees.First(x => x.FilePath.Equals(first.FileName, StringComparison.OrdinalIgnoreCase));
            //    var fsr = new FieldSplitterRewriter(annotationGroup, st, compilation);
            //    var newroot = fsr.Visit(st.GetRoot()).SyntaxTree.GetRoot();
            //    compilation = compilation.ReplaceSyntaxTree(st, SyntaxFactory.SyntaxTree(newroot, st.FilePath));
            //  }
            //}
            return(compilation);
        }
Esempio n. 2
0
    /// <summary>
    /// walk the syntax trees and replace each field declaration like int x,y,z
    /// with int x; int y; int z;
    /// if one of those has a readonly suggestion
    /// </summary>
    /// <param name="compilation"></param>
    /// <param name="annotations"></param>
    /// <returns></returns>
    private static Compilation SpiltReadOnlyFieldDeclarations(Compilation compilation, IEnumerable<ReadonlyField> annotations)
    {
      #region CodeContracts
      Contract.Requires(compilation != null);
      Contract.Requires(annotations != null);
      Contract.Ensures(Contract.Result<Compilation>() != null);
      #endregion CodeContracts

      // this is probably terribly ineffiecient, but once you modify the syntaxTree in anyway you have to get a new semantic model
      foreach(var annotation in annotations)
      {
        var st = compilation.SyntaxTrees.First(x => x.FilePath.Equals(annotation.FileName, StringComparison.OrdinalIgnoreCase));
        var fsr = new FieldSplitterRewriter(annotation, st, compilation);
        var newroot = fsr.Visit(st.GetRoot()).SyntaxTree.GetRoot();
        compilation = compilation.ReplaceSyntaxTree(st, SyntaxFactory.SyntaxTree(newroot, null, st.FilePath));
      }
      //foreach (var annotationGroup in annotations.GroupBy(x => x.FileName)) 
      //{
      //  if (annotationGroup.Any()) 
      //  {
      //    var first = annotationGroup.First();
      //    RBLogger.Info("Splitting fields in {0}", first.FileName);
      //    var st = compilation.SyntaxTrees.First(x => x.FilePath.Equals(first.FileName, StringComparison.OrdinalIgnoreCase));
      //    var fsr = new FieldSplitterRewriter(annotationGroup, st, compilation);
      //    var newroot = fsr.Visit(st.GetRoot()).SyntaxTree.GetRoot();
      //    compilation = compilation.ReplaceSyntaxTree(st, SyntaxFactory.SyntaxTree(newroot, st.FilePath));
      //  }
      //}
      return compilation;
    }