开发者

C# : Interface without Namespace

开发者 https://www.devze.com 2023-01-22 19:00 出处:网络
I generated an interface based off a WSDL definition file with wsdl.exe to use with a project.The resulting generated .cs file has the expected interface inside it, but the interface file doesn\'t hav

I generated an interface based off a WSDL definition file with wsdl.exe to use with a project. The resulting generated .cs file has the expected interface inside it, but the interface file doesn't have a namespace - the interface definition is directly below the using statements.

I've never seen a source code file without an explicitly declared namespace, which leads me to wonder: what are the benefits and drawbacks of not explicitly declaring a namespace? Is this a common thing to do with generated code?开发者_运维问答


The benefits are, I guess, less time spent typing in a namespace... You are able to specify the namespace you want as a parameter with wsdl.exe, and you should do so:

wsdl.exe /namespace:foo http://myreference/

The drawback is that without a namespace, you're that much more likely to have naming collisions with your objects. This problem gets more severe the more consumers there are of your class or interface. A namespace is definitely a good idea.


Usually code-generators have properties to specify namespace for the generated code. Namespaces provide logical grouping of the types, so they of course should be used to avoid ambiguities.


Namespaces are there to help you organise you're code and, primarily, to avoid naming collisions.

I would imagine there will be a way to specify the namespace for the generated code?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号