Why IDataSource Interface exists for ASP.NET and not for Winform?
I have looked at BindingSource class in wi开发者_StackOverflow社区nform and the datasource member type is Object (http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.datasource.aspx).
Wouldn't it be a better design if datasource was of IDataSource Class Interface like it seems in ASP.NET ?
Having a property of type object allows you to set anything as a data source. Then, the BindingSource
is responsible of the transformation. It's only a convenience matter.
From the page you link in you question, if you set to the property:
a null reference, the data source will be an empty
IBindingList
of objects. Adding an item sets the list to the type of the added item.a non-list type or object of type "T", you'll get an empty
IBindingList
of type "T".an array instance, and it will be a
IBindingList
containing the array elements.an
IEnumerable
instance will be transformed into anIBindingList
containing theIEnumerable
items.a List instance containing type "T", and the data source will be an
IBindingList
instance containing type "T".
It seems less safe, since it's not strongly typed, but it appears to be pretty handy.
精彩评论