I've got a situation where I have data classes that are generated by a database with various properties on them e.g which I cannot modify.
public DataClass
{
public string PropertyX {get; set;}
public int PropertyY {get; set;}
public float PropertyZ {get; set;}
}
Some of these classes may have 20 or so properties. When updating the data a "transient" copy of the "persistent" data is made, then the properties updated on the transient and copied from the transient to persistent.
Which is fine although if only changing one property isn't very efficient.
I wanted to find out if there is a way in c# that I could create a list of flagged properties or add attributes onto certain flagged properties I wish to update.
So the end result would be (please note this is all pseudo)
DataClass transientObj = new DataClass(Transient);
[FlagPropertyToUpdate] //This is the bit I have no idea how to do
transientObj.propertyX = "updateOnlyMe!";
DataClass persistantObj = new DataClass(Persistant);
UpdateData dataUpdater = new UpdateData(transientObj,persistantObj)
dataUpdater.save();
public UpdateData
{
public void save(){
//some how know to only update propertyX and not all three properties
}
public UpdateData(DataClass trans, DataClass pers)
}
Any assistance on how I could go about doing this (and if its possible) would be highly appreciated!