How to get the assembly name and class name with full namespace of a given class in the solution?

前端 未结 4 1425
耶瑟儿~
耶瑟儿~ 2021-01-02 10:33

I\'m working with WPF and often have the need to get the namespace and assembly name of a given class. But I don\'t know how to do this.

So, how can we get the name

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 11:04

    These should give you what you're after:

    var assemblyName = typeof(ClassNameGoesHere).AssemblyQualifiedName;
    var namespaceOfClass = typeof(ClassNameGoesHere).Namespace;
    

    I see you've just added a note to your question regarding "when browsing the classes in the Solution Explorer", the simple answer is that as far as I know, you can't because that's not what Solution Explorer is for (it's there for browsing the files in a solution, not what's contained inside them) and also because:

    1. One file can contain multiple classes
    2. All files in one project will, generally, always compile down to a single assembly, making it redundant to display that name for each file.

    You may want to see if the "Class View" gives you what you want, but, I suspect it won't.

提交回复
热议问题