I'm in a situation where I could use AutoMapper. But property names on my objects are different and AutoMapper mapping will additional effort for this just one odd usage.
here is my code looks like now
ObjectOne.PropOne = ObjectOne.PropOne.CopyFrom(ObjectTwo.PropX)
Extension method looks like below -
public static T CopyFrom<T, U>(this T target, U source)
{
bool isValidString = (source is string && source != null && !string.IsNullOrEmpty(source.ToString()));
bool isValidNonString = (!(source is string) && source != null);
if (isValidString || isValidNonString)
target = Utils.GetValue<T>(source);
return target;
}
is there a way where I can avoid the assignment and can do like below?
ObjectOne.PropOne.CopyFrom(ObjectTwo.PropX)