I want to write a code snippet which does following thing, like if I have a class let's say MyClass:
class MyClass
{
public int Age { get; set; }
public string Name { get; set; }
}
so the snippet should create following method:
public bool DoUpdate(MyClass myClass)
{
bool isUpdated = false;
if (Age != myClass.Age)
{
isUpdated = true;
Age = myClass.Age;
}
if (Name != myClass.Name)
{
isUpdated = true;
Name = myClass.Name;
}
return isUpdated;
}
So the idea is if I call the snippet for any class it should create DoUpdate
method and should write all the properties in the way as I have done in the above example.
So I want to know :
- Is it possible to do the above ?
- If yes how should I start, any guidance ?
bool DoUpdate<T>(this T target, T source)
, for example - then: no snippets required! – Cayser