I am using some 3rd party library that exposes some type (returned by a method).
This type has some protected fields i am interested in, however i am not able to use them since their visibility is protected.
Here is a simplification of the problem:
public class A
{
protected object Something;
public A Load()
{
return new A();
}
}
public class ExtendedA : A
{
public void DoSomething()
{
// Get an instance.
var a = Load();
// Access protected fields (doesn't compile).
a.Something = ....
}
}
Is there any easy way to achieve this?
Description
You can access the Field using
this.Somethingbecause your class is derived fromclass A.If you want to create a instance of the
class A, not your derived class, you can only access the field using reflection.Sample using Reflection
More Information