Every now and then you need to create a wrapper object to keep things nice ‘n’ tidy in your code. For example, you might want to wrap the sealed SqlDataReader class with your own class, maybe called SafeDataReader (as in Rockford Lhotka’s most excellent CSLA.Net architecture), to handle null values gracefully so you don’t have to include checks for null values throughout your code.
Since SqlDataReader is a sealed class, you can’t inherit from it. Bummer. And creating a wrapper is a ton of work because of all the members exposed by SqlDataReader.
This is where CodeToaster can save you a ton of work by generating a fully functional wrapper class in less than 15 seconds!
To use the template, you will need CodeToaster (just updated today with a slew of bug fixes and enhancements).
Create a new template project and copy the wrapper template into it: get the wrapper template here.
Now, compile the project, and set the template’s properties thusly (depending on the class you want to wrap):
Now run the template, and you should end up with a bee-youtiful wrapper class that you didn’t spend a billion years coding.
[Disclaimer: I put this template together in about 30 minutes, so there may still be a few bugs. But this is a good example of what CodeToaster (and code generation in general) can do.]