I have an event class defined as the following:
[Serializable]
[DataContract]
public class BaseEvent
{
[DataMember]
public int count { get; set; }
[DataMember]
public SubEventClass SubEventClass { get; set; }
}
and a SubEventClass defined as the following:
[Serializable]
[DataContract]
public class SubEventClass
{
[DataMember]
public int Width { get; set; }
[DataMember]
public long Length { get; set; }
[DataMember]
public long Area { get; set; }
}
I expected to merge/sum two BaseEvent objects values by calling this method:
public static BaseEvent MergeQueryShapeStats(BaseEvent obj1, BaseEvent obj2)
{
obj1.count += obj2.count;
var properties = typeof(SubEventClass).GetProperties();
foreach (var prop in properties)
{
var value = prop.GetValue(obj2.SubEventClass, null);
if (value != null)
prop.SetValue(obj1.SubEventClass, value, null);
}
return obj1;
}
This following code, to my knowlege, just sets values from obj2 to obj1:
prop.SetValue(obj1.SubEventClass, value, null);
Does anybody know how to sum values of obj2 and reset obj1?
Thanks
Oh. It's resolved by the following change:
change the prop type to long in SubEventClass
call this method: