Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add switch to include private members in PE symbols #5049

Open
bkoelman opened this issue Sep 6, 2015 · 6 comments
Open
Labels
Area-Interactive Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request
Milestone

Comments

@bkoelman
Copy link
Contributor

bkoelman commented Sep 6, 2015

In Roslyn v1.0, private fields/properties/methods (and nested types) are not exposed by calls like INamedTypeSymbol.GetMembers(), in case such a type was constructed from a referenced assembly instead of source code.

For the project I'm currently working on (backporting a Roslyn-based analyzer into FxCop rules for use in previous versions of Visual Studio), I would like a switch to become available in Roslyn vNext, to include private members.

For example, when exposed through MetadataReferenceProperties, I could write code like:

private static CSharpCompilation CreateCompilation(AssemblyNode assemblyNode)
{
    SyntaxTree tree = CSharpSyntaxTree.ParseText(" ");

    MetadataReferenceProperties referenceProperties =
        MetadataReferenceProperties.WithPrivateMembers;

    IEnumerable<MetadataReference> assemblyReferences = new[]
    {
        MetadataReference.CreateFromFile(assemblyNode.Location, referenceProperties),
        MetadataReference.CreateFromFile(typeof (object).Assembly.Location)
    };

    string outputAssemblyFileName = Path.GetFileName(Path.GetTempFileName()) + ".dll";

    return CSharpCompilation.Create(outputAssemblyFileName,
        options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
        syntaxTrees: new[] { tree }, references: assemblyReferences);
}
@bkoelman
Copy link
Contributor Author

bkoelman commented Sep 6, 2015

@shyamnamboodiripad

@shyamnamboodiripad
Copy link
Contributor

cc @AlekseyTs @jaredpar

@shyamnamboodiripad shyamnamboodiripad added Concept-API This issue involves adding, removing, clarification, or modification of an API. Area-Compilers labels Sep 8, 2015
@tmat
Copy link
Member

tmat commented Sep 8, 2015

This is also gonna be needed to support #r! scripting directive (add a reference with internals visible).

@gafter gafter added this to the 1.2 milestone Sep 8, 2015
@AlekseyTs
Copy link
Contributor

Would making CompilationOptions.MetadataImportOptions public address the gap?

@tmat
Copy link
Member

tmat commented Sep 8, 2015

@AlekseyTs We will need to do this per-reference for scripting, not per-compilation.

@bkoelman
Copy link
Contributor Author

@AlekseyTs Thanks for pointing out CompilationOptions.MetadataImportOptions, I was unaware of its existence. To investigate, I tried setting it through reflection. Most things are working for me that way, but I ran into something of which I'm not sure is correct.

Making this public would be nice. But a have an acceptable workaround at the moment. So holding this off in favour of doing what's needed for scripting would be fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request
Projects
None yet
Development

No branches or pull requests

8 participants