public class myclass
{
public int mymember { get; set; }
}
class MySetterClass<T>
{
// obj.mymember = o for myclass
public static void SetMember(string membername, object o, ref T obj)
{
}
}
Can I do this with Reflection API ?
I have a generic class and I want to set a member of an instance.
Thanks in advance!
You can, but I’d warn against it. You are essentially doing an end-run around the type safety system, and there are a lot of pitfalls there.
If you must, the code is something like this, assuming that the member in question is a Property and not a Field: