I often find the need to do something along these lines:
public class OperationResult { bool succes; SomeOtherObject someobject; } public interface ICanDoSomethingWeird { OperationResult DoMyThing(); }
Where the OperationResult is really a class that belongs to the ICanDoSomethingWeird interface. I find it very annoying I cannot place it in the namespace of the interface. I’m wondering how other people deal with this. Do you just stick it in the global namespace? or just one namespace up from the namespace where the interface sits?
My current approach is to do rename the OperationResult class to ICanDoSomethingWeird_OperationResult, but am not very impressed by how pretty that is 🙂
Anybody have a better solution?
If
OperationResultis a type used solely byICanDoSomethingWeirdand clients ofICanDoSomethingWeird, then it belongs in the same ‘context’ asICanDoSomethingWeird. That is, it belongs in the same namespace asICanDoSomethingWeird:Think about the client code. Would you prefer this:
or this:
The latter makes more sense to me, and is the only option where interfaces are concerned. You cannot declare inner types in interfaces. And do note the general advice regarding nested types: