dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.99k stars 4.03k forks source link

Invalid code sample in Wiki page #28725

Open droosma-1 opened 6 years ago

droosma-1 commented 6 years ago

So i tried to find a way to pull request this but i could not find it.

on Getting Started C# Syntax Transformation there is a code sample near the end of the page

private static Compilation CreateTestCompilation()
{
    String programPath = @"..\..\Program.cs";
    String programText = File.ReadAllText(programPath);
    SyntaxTree programTree =
                   CSharpSyntaxTree.ParseText(programText)
                                   .WithFilePath(programPath);

    String rewriterPath = @"..\..\TypeInferenceRewriter.cs";
    String rewriterText = File.ReadAllText(rewriterText);
    SyntaxTree rewriterTree =
                   CSharpSyntaxTree.ParseText(rewriterText)
                                   .WithFilePath(rewriterPath);

    SyntaxTree[] sourceTrees = { programTree, rewriterTree };

    MetadataReference mscorlib =
            MetadataReference.CreateFromAssembly(typeof(object).Assembly);
    MetadataReference codeAnalysis =
            MetadataReference.CreateFromAssembly(typeof(SyntaxTree).Assembly);
    MetadataReference csharpCodeAnalysis =
            MetadataReference.CreateFromAssembly(typeof(CSharpSyntaxTree).Assembly);

    MetadataReference[] references = { mscorlib, codeAnalysis, csharpCodeAnalysis };

    return CSharpCompilation.Create("TransformationCS",
                                    sourceTrees,
                                    references,
                                    new CSharpCompilationOptions(
                                            OutputKind.ConsoleApplication));
}

I believe there are 6 error's in there

String programPath = @"..\..\Program.cs"; should be String programPath = @"..\..\..\Program.cs";

String rewriterPath = @"..\..\TypeInferenceRewriter.cs"; should be String rewriterPath = @"..\..\..\TypeInferenceRewriter.cs";

String rewriterText = File.ReadAllText(rewriterText); should be String rewriterText = File.ReadAllText(rewriterPath);

MetadataReference mscorlib = MetadataReference.CreateFromAssembly(typeof(object).Assembly); should be MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);

MetadataReference codeAnalysis = MetadataReference.CreateFromAssembly(typeof(SyntaxTree).Assembly); should be MetadataReference codeAnalysis = MetadataReference.CreateFromFile(typeof(SyntaxTree).Assembly.Location);

MetadataReference csharpCodeAnalysis = MetadataReference.CreateFromAssembly(typeof(CSharpSyntaxTree).Assembly); should be MetadataReference csharpCodeAnalysis = MetadataReference.CreateFromFile(typeof(CSharpSyntaxTree).Assembly.Location);

If I have missed the feature to change it my self. Please point me to the correct place and close this issue.

Youssef1313 commented 3 years ago

@droosma-1 The wiki was moved to the repository. You can open a PR against these files:

https://github.com/dotnet/roslyn/blob/master/docs/wiki/Getting-Started-VB-Syntax-Transformation.md https://github.com/dotnet/roslyn/blob/master/docs/wiki/Getting-Started-C%23-Syntax-Transformation.md