This question already has answers here:
Getting all types in a namespace via reflection
(11 answers)
Closed 9 years ago.
How can I get all classes inside a namespace?
You cannot. Classes are not "in" namespaces. Classes have namespaces as part of their name.
The classes "in" a namespace may reside in multiple assemblies. For example, some of the types in the System namespace reside in mscorlib.dll, and others reside in System.dll. You would have to go through all of the types in all of the assemblies you could find to be certain that you had found all the types "in" a particular namespace.
As #hawk mentioned, the answer is located here, with sample code that you can use:
Getting all types in a namespace via reflection
Use Reflector to see them (assuming that all the classes are in the same assembly).
Related
This question already has answers here:
c# Where can find System.Windows.Controls.dll
(3 answers)
Closed 8 years ago.
I'm trying to add a reference to the namespace System.Windows.Controls in a library project, but i can't find it in the list. Does anybody know what is going on? i'm using 4.0. I want to add system.window.controls.dll but the library is not complete, how can i make it complete?
You have to look for this System.Windows.Controls.Data.dll assembly. In this assembly, there is the namespace you are looking for.
In general, a namespace and it's types may be in an assembly with different name than the namespace name.
This question already has answers here:
Can't find System.Windows.Media namespace?
(7 answers)
Closed 8 years ago.
I can't seem to find System.Windows.Media reference for my C# project. It is not there at all!
Help and tips?
System.Windows.Media is a namespace - most of the types within it are in the assembly PresentationFramework.dll or PresentationCore.dll.
You should look up whichever type you're interested in (via MSDN), and check which assembly it's in. You've got to distinguish between namespaces and assemblies - they're different concepts. You add a reference to an assembly as part of the project configuration, but specify the namespace in your source code (usually via a using directive).
System.Windows.Media is not a reference, it is a namespace.
This namespace belongs on PresentationFramework.dll or PresentationCore.dll
Namespace: System.Windows.Media
Assembly: PresentationFramework (in PresentationFramework.dll)
You can add these dll files in your current project and then you can use it via using.
using System.Windows.Media;
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can attributes be added dynamically in C#?
Is it possible to assign .net Attribute to class/method programmatically?
For example:
Can I decorate my custom .net com classes with Guid/ProgId attributes taken from external file? Something like:
typeof(MyComObject).AssignAttribute(new GuidAttribute("..."));
instead of hardcode like:
[Guid("...")]
class MyComObject
{
}
Thank you in advance!
It depends. ICustomTypeDescriptor allows to almost anything you want to almost every part of a class (which might not even exist for that matter), but this particular interface might not be used by whatever system you're trying to feed your object to. PropertyGrid uses this interface extensively, though.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What are reasons why one would want to use nested classes?
I found some example code online for something unrelated, and it had nested classes. I thought this was a mistake, and the outer one should have been Namespace, but the code compiled and worked fine.
What are nested classes used for? Is this a good programming practice?
So that you don't litter a namespace with classes. Inner, nested classes are visible only to the parent class, or when typing ParentClass.*, rather than spamming the namespace with classes that are only ever used once by one single class
It allows you to logically group all elements of a class within a single file (including subclasses)
More maintainable. It's easier to read small classes in its parent class rather than having to open another file to read a few lines
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get Namespace of an Assembly?
when i load a assembly how can i find its namespace suppose if i load a exam.dll how can i find its namespace
First off, an assembly can contain many namespaces. It's often that 1 assembly == 1 namespace, but this is not required at all.
To find the namespaces in the assembly, just get all of the types in the assembly. See Assembly.GetTypes for details as to how to do this.
From the type, you have the fully qualified type name, and the namespace of the type.