Disposable Base Class

I have covered the IDisposable interface in my previous posts IDisposable and using in C# and Implementing IDisposable. To make the implementation of IDisposable easier, I have written an abstract base class that handles the details of the IDisposable pattern. The objectives of the class is to:

  • Provide a simple, reusable implementation of the disposable pattern.
  • Pass all code analysis rules.

Code Generation – Blessing or Curse?

There are lot of code generation tools available. Microsoft Visual Studio has had code generation possibilities since I started using it in the mid 90-ties. Code generation can be a blessing for getting something up and running quickly, but also a curse when maintaining code.

Whenever a code generation tool is considered, there are two very important aspects that need to be considered:

  • Is there support for regeneration when the code needs to be updated?
  • Are there possibilities to make adaptions without loosing them on regeneration?

Unfortunately a lot of the tools fail on at least one of these points. The blessing that helped creating something working quickly becomes a curse during further development and maintenance.

Data Binding a Single Object when IEnumerable is Expected

Controls that can be used with data binding typically expect some kind of collection as the data source. One example is the ASP.NET DetailsView control. It displays a single record, but still expects a collection (to be exact: something that implements IEnumerable) to be assigned to its DataSource property.

I use a small extension method called WrapInEnumerable to help in this situation:

public static class ObjectExtensions
    public static IEnumerable<T> WrapInEnumerable<T>(this T t)
        yield return t;

With this function it is easy to use the DetailsView for displaying a single object:

myDetailsView.DataSource = myDataObject.WrapInEnumerable();
Software Development is a Job – Coding is a Passion

I'm Anders Abel, an independent systems architect and developer in Stockholm, Sweden.

profile for Anders Abel at Stack Overflow, Q&A for professional and enthusiast programmers

Code for most posts is available on my GitHub account.

Popular Posts



Powered by WordPress with the Passion for Coding theme.