Some background: We require all of our DTO objects to be serializable so that they can be stored in session or cached.
As you can imagine, this is extremely annoying and prone to error… is there any automated way (ideally as part of the build process) using Visual Studio 2010 to ensure that all classes in a namespace are marked with the [Serializable] attribute?
You can’t find all possible classes in a namespace – but you can find all classes within a given assembly which have the specified namespace, and check those.
Assert that
badClassesis empty in whatever way you want 🙂EDIT: As mentioned in the comments, the
IsSerializableproperty is kinda handy here 🙂