Пример #1
0
		/// <summary>
		///     Normalizes the <paramref name="syntaxTree" /> of the <see cref="Compilation" />.
		/// </summary>
		/// <param name="syntaxTree">The syntax tree that should be normalized.</param>
		protected override SyntaxTree Normalize(SyntaxTree syntaxTree)
		{
			var root = syntaxTree.GetRoot();
			var firstNode = root.GetFirstToken(true, true, true, true).Parent;
			var updatedNode = firstNode.PrependLineDirective(1, syntaxTree.FilePath);

			return syntaxTree.WithFilePath(syntaxTree.FilePath + Guid.NewGuid()).WithRoot(root.ReplaceNode(firstNode, updatedNode));
		}
Пример #2
0
            private static SyntaxTree ToResult(Compilation compilation, string name, SyntaxTree tree, string path, bool writeToDisk)
            {
                var ext = (compilation.Language == LanguageNames.VisualBasic) ? ".vb" : ".cs";
                var fileName = $"{FixUpName(name)}{ext}";
                path = PathUtilities.CombinePossiblyRelativeAndRelativePaths(path, fileName);

                if (writeToDisk)
                {
                    var sourceText = tree.GetText();
                    var encoding = sourceText.Encoding ?? Encoding.UTF8;
                    PortableShim.File.WriteAllText(path, sourceText.ToString(), encoding);
                }

                return tree.WithFilePath(path);
            }
Пример #3
0
            private static SyntaxTree ToResult(Compilation compilation, string name, SyntaxTree tree, string path, bool writeToDisk)
            {
                var ext      = (compilation.Language == LanguageNames.VisualBasic) ? ".vb" : ".cs";
                var fileName = $"{FixUpName(name)}{ext}";

                path = PathUtilities.CombinePossiblyRelativeAndRelativePaths(path, fileName);

                if (writeToDisk)
                {
                    var sourceText = tree.GetText();
                    var encoding   = sourceText.Encoding ?? Encoding.UTF8;
                    PortableShim.File.WriteAllText(path, sourceText.ToString(), encoding);
                }

                return(tree.WithFilePath(path));
            }