Is there a way to reach a `protected` member of another object from a derived type?

Last time I faced a similar problem, I used the solution of adding a protected static method to the base:

class MyBase
{
    protected object PropertyOfBase { get; set; }

    protected static object GetPropertyOfBaseOf(MyBase obj) 
    {
        return obj.PropertyOfBase;
    }
}

class MyType : MyBase
{
    void MyMethod(MyBase parameter)
    {
        object p = GetPropertyOfBaseOf(parameter);
    }
}

Leave a Comment