Monday, December 17, 2007

WinForms inheritance workaround

I've started some days ago with a simple mini-guide for creating Windows Forms Applications with NHibernate. It's not finished yet but what's interesting because I wanted to have visual inheritance in my application + using Generics. I initially thought that this should not be a problem but i was wrong.

After adding Generics support to my Forms + creating abstract Form , the Designer stopped working with one of those "ugly design-time errors" , which BTW are very nicely shown in 2008.
So my conclusion is : neither 2005 nor 2008 can easily support Generics + USer Control (or forms) inheritance (they both share this same "bug" / limitation ).

Luckily I found this workaournd from Frank Bakker .I could work-around and create a common/base UserControl for my Business Object UI.

Code Example:

public partial class ProductFormUC : ProductFormUCDummy
public ProductFormUC() : base()

public ProductFormUC(int pProductID) : this()
Product product = this.Repository.ProductDAO.Fetch(pProductID);
if (product == null)
throw new Exception("Not Found : was it deleted? improve this case");


categoryBindingSource.DataSource = this.Repository.CategoriesDAO.GetAll();
categoryBindingSource.DataMember = "CategoryName";

productBindingSource.DataSource = product;



This "intermediate" class makes the trick :
public partial class ProductFormUCDummy : BaseBOFormUC
protected override IDAO DAO
get { return this.Repository.ProductDAO; }



Anonymous said...

Genial post and this post helped me alot in my college assignement. Say thank you you seeking your information.

Anonymous said...

[b]Prestigio 5120[/b]

Prestigio GeoVision 5120 – это современные GPS-навигаторы с большим экраном, которые позволят Вам добираться до пункта назначения с минимальными усилиями и затратами. Эти устройства достаточно компактны. Их можно везде носить с собой или быстро установить в автомобиле для дорожной навигации. GPS-навигаторы Prestigio GeoVision 5120 позволят Вам путешествовать легко и без ограничений, кроме того, они удивят Вас набором мультимедийных функций, что позволит Вам приятно провести время в долгой дороге.


Anonymous said...

Хорошая статья. Действительно было интересно почитать. Не часто такое и встречается та.Наверное стоит подписаться на ваше RSS

buy viagra said...

Nice work very professional weblog!!
viagra online
generic viagra
thanks for sharing!!!