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: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.