Is it possible to get or set private fields?
I want to get System.Guid.c. Is there a way to access it or should I just copy the code from the strut and
You can have an extension method to get any private field of any type:
public static T GetFieldValue(this object obj, string name) {
var field = obj.GetType().GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
return (T)field?.GetValue(obj);
}
And then access a private field of an arbitrary type:
Guid id = Guid.NewGuid();
Int16 c = id.GetFieldValue("_c");