Is there a way to 'fake' header files in C# using namespaces? From what I've heard, there is no way to get the preprocessing that they provided in C++; but I'd like the organization aspect of it rather than wrapping classes in namespaces and relying on an IDE to tell me whats in what.
for example (not开发者_如何学运维e the incorrect syntax) suppose
ns1.cs
iamaclass.cs
iamanotherclass.cs
yaclass.cs
yaaclass.cs
where ns1.cs 's contents are:
namespace ns1
{
extern class iamaclass;
extern class iamanotherclass;
namespace ns1-nested
{
extern class yaclass
extern class yaaclass
}
}
If you make the directory structure of your projects match the namespace structure, this goes a long way toward getting the organizational benefits. Now your project file and associated directory structure contains all of the information proposed in your 'header' file.
There is no way to do this in C#. The closest you could get is to make your ns1.cs file and fill it with partial class ....
, but that is really pointless. At that point you should just write a document as you won't really get any compiler help in enforcing the structure.
I would say this is a case of "forget how you did it in C++". Usually it's not important to find out what's inside a namespace, but more important to figure out what namespace a certain class is in, and C#'s organization will show you that perfectly.
Just a small last thing: is there a practical reason you don't want to rely on an IDE, or is it just a nitpick? It's OK to rely on the help of an IDE for much development.
精彩评论