Is nesting types considered bad practice?
- by Rob Z
As noted by the title, is nesting types (e.g. enumerated types or structures in a class) considered bad practice or not? When you run Code Analysis in Visual Studio it returns the following message which implies it is:
Warning 34 CA1034 : Microsoft.Design :
Do not nest type
'ClassName.StructueName'.
Alternatively, change its
accessibility so that it is not
externally visible.
However, when I follow the recommendation of the Code Analysis I find that there tend to be a lot of structures and enumerated types floating around in the application that might only apply to a single class or would only be used with that class. As such, would it be appropriate to nest the type sin that case, or is there a better way of doing it?