When have very large class, with 50 properties and you need to clone it, then you may be using extension method, then you have to type each property copy logic. To generate the lines use the following JS code. It’s not 100% correct, but will get you through quickly:
var item = `
public virtual T Id { get; set; }
public virtual DateTimeOffset CreatedDateTime { get; set; } = DateTimeOffset.UtcNow;`;
var nameOfObj = 'copyFromObject';
var split = item.split(" { get; set; ");
var output = '';
for (var prop of split) {
var splitAGain = prop.split(" ");
if (splitAGain.length) {
var propName = splitAGain.pop();
output = `${output}\n${propName} = ${nameOfObj}.${propName},`
}
}
console.log(output)
Yes, you can use reflection. But it is very error prone (At least for me, because I don’t have much experience with it.).
Cheers and Peace Out!!!