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

Idea: fullnameof() #2154

Closed
janniksam opened this issue Jan 18, 2019 · 8 comments
Closed

Idea: fullnameof() #2154

janniksam opened this issue Jan 18, 2019 · 8 comments

Comments

@janniksam
Copy link

I like the nameof() functionality that was implemented a few versions ago.

I would love to have a similar functionality for full namespace:

An example:
[ServiceInterface(Name = nameof(IServiceInterface), ConfigurationName = "Foo.Bar.Test.IServiceInterface")]
public interface IAsyncServiceInterface : IServiceInterface

Could look like this:
[ServiceInterface(Name = nameof(IServiceInterface), ConfigurationName = namespaceof(IServiceInterface))]
public interface IAsyncServiceInterface : IServiceInterface

What you guys think about it?

@Unknown6656
Copy link
Contributor

The namespace of a type abc.def.ghi is usually abc.def (leaving aside the possiblity of nested types). To retrieve this string, one usually uses typeof(....).Namespace or .....GetType().Namespace.

To retrieve the fully qualified type name, one uses typeof(....).FullName or .....GetType().FullName.
This -- as far as I understood your aim correctly -- is the string you are interested in.

What exactly are you proposing? A compile-time constant resolution of the Properties Type.Namespace and Type.FullName?
What are real-world applications of this feature? (considering that compile-time "constant" instances of System.Type are allowed to be passed to attributes)

@svick
Copy link
Contributor

svick commented Jan 18, 2019

If you actually want the full name of the type, not just the namespace, then I think this is a duplicate of #701.

@alrz
Copy link
Member

alrz commented Jan 18, 2019

one usually uses typeof(....).Namespace

I think there was a proposal to make those compile-time constants so you can use it in attributes (or any const context).

@janniksam
Copy link
Author

Yes, I am sorry, you guys are right. it IS a duplicate of #701 :)

@svick
Copy link
Contributor

svick commented Jan 18, 2019

@alrz I think you're talking about dotnet/roslyn#10972.

@janniksam janniksam changed the title Idea: namespaceof() Idea: fullnameof() Jan 19, 2019
@jnm2
Copy link
Contributor

jnm2 commented May 13, 2020

@janniksam Could you close this one please since you've linked to the original?

@333fred
Copy link
Member

333fred commented May 13, 2020

Closing as a duplicate.

@333fred 333fred closed this as completed May 13, 2020
@jnm2
Copy link
Contributor

jnm2 commented Oct 11, 2024

This would be addressed by a proposal to make typeof(IServiceInterface).Namespace a constant, usable in the sample you gave. #8505

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants