TL;DR - What is the expected usecase for (Hyper)TypeDescriptors instead of PropertyInfo for at runtime typeless property access?
I am used to something akin to the following
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (PropertyInfo property in properties)
{
property.SetValue(this, reader[property.Name], null);
}
Now this is clearly a very simplified version but this is a basic Load() method and works well and executes pretty fast. If I change this over to using the TypeDescriptors w/ the HyperTypeDescriptor it looks a bit like
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this);
foreach (PropertyDescriptor pd in pdc)
{
pd.SetValue(this, reader[pd.Name]);
}
They look basically the same, and if I was spending a lot of time in the foreach loops the HyperTypeDescriptor is much faster for basic Get/Set Value access.. But when you factor in the TypeDescriptor.GetProperties() vs typeof(T).GetProperties() it is noticeably slower. This leads me to wonder if this is even the proper usecase of the HyperTypeDescriptor library.
The more detailed information is that I am looking to automate a lot of the repetitive code of defining data types in C# and then supporting serialization of the data to and from multiple data sources (Database, XML, Stream and DataBinding for example). The HyperTypeDescriptor library came to my notice when I am looking into the DataBinding area to make it automatically inject INotifyPropertyChanged event handling into default Properties (if I can figure out how to do that) but I was looking at extending its use through out the tools I am writing to increase file IO times. A database or a file is always going to be slower, but I do like to try and improve execution speeds where I can.
Aucun commentaire:
Enregistrer un commentaire