I am implementing an instance of IBindingListView for a UI binding scenario. This is a fairly complex undertaking, given also that the list is relying on some dynamically generated runtime code to avoid reflection yet give the list the flexibility in dealing with multiple types. Ultimately, I need knowledge of the properties of the type being displayed in the list, so I can parse the IBindingListView.Filter property string and behave correctly under a call to IBindingListView.ApplySort. Enter System.ComponentModel.PropertyDescriptor and the related type description API.
Since I will be dealing with potentially incorrectly cased values in the filter, I need to know how to get a property out of the PropertyDescriptorCollection regardless of case. There is an .Item property, mmm, ok… but what about case? The ‘Remarks’ section comes to the rescue (as jfo also observes at her new digs):
The Item property is case-sensitive when searching for names. That is, the names “Pname” and “pname” are considered to be two different properties.
This is not the first time that the Remarks section has helped me out. Indeed, it is often the only valuable information in my effort to understand the behavior of the type or operation. This is good to consider when decorating my own types with the <remarks></remarks> xml doc tag – what does the user of this API need to know to eliminate having to make explorations with mockup code?
Now, if only the same existed for expected behavior for an IBindingListView’s ‘Contains’, ‘Find’ and ‘IndexOf’ methods in the presence of a non-null ‘Filter’. I suppose this is where MSDN Community Comments come in.
Filed under: Code Kaizen