0

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 (note 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
   }
}
4

2 に答える 2

2

プロジェクトのディレクトリ構造を名前空間構造と一致させると、組織のメリットを得るのに大いに役立ちます。これで、プロジェクト ファイルと関連するディレクトリ構造に、「ヘッダー」ファイルで提案されたすべての情報が含まれます。

于 2011-01-20T16:05:15.093 に答える
0

C# でこれを行う方法はありません。最も近い方法は、ns1.cs ファイルを作成して .cs ファイルで埋めることですpartial class ....が、それは本当に無意味です。その時点で、構造を強制する際にコンパイラーの助けが実際に得られないため、ドキュメントを作成する必要があります。

これは、「C++ でどのように行ったかを忘れる」場合と言えます。通常、名前空間の内容を把握することは重要ではありませんが、特定のクラスがどの名前空間に含まれているかを把握することはより重要です。C# の構成はそれを完全に示します。

最後に、IDE に頼りたくない実用的な理由はありますか? 多くの開発で IDE の助けを借りても問題ありません。

于 2011-01-20T16:04:28.477 に答える