I have bunch of data objects that I populate after getting data from a feed. The feed is unreliable and sometimes drops data. I need to merge the incoming data with the data that I already have. I am unable to figure out an easily extendable and scalable pattern for that.
For example, my datamodel has the following field
DataModelExample
{
public string Name;
public string Value;
public string Extension;
}
If the feed drops the field Value, it is okay for me to pick data from an existing data object from cache and merge the two. I have a number of data objects with varying number of fields where this needs to be done.
Any ideas?
One possible way:
You could change all your property definitions so they are all
nullable.For instance, if you have a
public int MyInt { get; set; }property, change it topublic int? MyInt { get; set; }Then, after your object has been populated from your feed, you could iterate over all your properties using reflection (see How to loop through all the properties of a class?) and for each property, if the value is null (which means the feed drops the property), set it with a value that comes from your cache.