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?
精彩评论