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

Cannot get internal members of a Type from within INamedTypeSymbol #24412

Closed
npolyak opened this issue Jan 24, 2018 · 6 comments
Closed

Cannot get internal members of a Type from within INamedTypeSymbol #24412

npolyak opened this issue Jan 24, 2018 · 6 comments
Labels
Area-Compilers Question Resolution-Answered The question has been answered Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@npolyak
Copy link

npolyak commented Jan 24, 2018

I am getting a referenced type from a Roslyn Compilation by using Compilation.GetTypeByMetadataName(...) method. Then I use INamedTypeSymbol.GetMembers() method to get all its member symbols. I am getting all public and protected symbols but neither private nor internal. I do not care much about private member symbols, but internals are a must for me. Is there any way to get them from a Roslyn compilation?

@jcouv
Copy link
Member

jcouv commented Jan 24, 2018

You may be looking for the ignoreAccessbility parameter on Compilation.GetSemanticModel(...).

@jcouv jcouv added Question Area-Compilers Resolution-Answered The question has been answered labels Jan 24, 2018
@npolyak
Copy link
Author

npolyak commented Jan 24, 2018

I am not even using semantic model - I do not need it for my purpose. Just pulling the type straight from the compilation and checking its members. Can you give me a code example?

This is not my code that I am investigating - this code is referenced by my code.

@npolyak
Copy link
Author

npolyak commented Jan 24, 2018

It seems like I resolved the problem but not without a hack.

one has to set a hidden property MetadataImportOptions of the compilation to MetadataImportOptions.All (which is 2). Both the CSharpCompilationOptions.MetadataImportOptions member and MetadataImportOptions enumeration are internal to Microsort.CodeAnalysis assembly. I had to use reflection to be able to set it. In particular I did something like:

MethodInfo withMetadataImportOptionsMethodInfo = 
  typeof(CSharpCompilationOptions).GetMethod("WithMetadataImportOptions, BindingFlags.NonPublic | BindingFlags.Instance);

MyCompilationOptions = 
    (CSharpCompilationOptions) withMetadataImportOptionsMethodInfo.Invoke(MyCompilationOptions, (byte) 2);

(byte) 2 is the MetadataImportOptions.All option.

@npolyak
Copy link
Author

npolyak commented Jan 24, 2018

I opened #24425 requesting to open up the API for setting MetadataImportOptions.
I'll keep this issue open for now in case some one can come up with a better way of achieving this.

@jcouv
Copy link
Member

jcouv commented Feb 2, 2018

MetadataImportOptions will be made a public API in 15.7. See #24468
I'll go ahead and close the issue. Thanks

@jcouv jcouv closed this as completed Feb 2, 2018
@jcouv jcouv added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Feb 2, 2018
@jcouv jcouv added this to the 15.7 milestone Feb 2, 2018
@npolyak
Copy link
Author

npolyak commented Feb 2, 2018

cool thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Question Resolution-Answered The question has been answered Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

2 participants