Without access to the type (and not "InternalsVisibleTo", etc.) you will have to use reflection. But the best question would be: should you access this data? This is not part of a public type contract ... it sounds to me as if it was being considered as an opaque object (for their purposes, not for you).
You described it as a public instance field; to get this through reflection:
object obj = ... string value = (string)obj.GetType().GetField("test").GetValue(obj);
If this property is actually (and not a field):
string value = (string)obj.GetType().GetProperty("test").GetValue(obj,null);
If it is not publicly available, you need to use the BindingFlags GetField / GetProperty overload.
Important aside : be careful with this reflection; the implementation may change in the next version (crack your code), or it may be confused (break your code), or you may not have enough "trust" (violation of your code). Are you viewing a template?
Marc Gravell May 28 '09 at 1:32 p.m. 2009-05-28 13:32
source share