Input code
var cat = new Cat();
cat.Test();
public class Cat : Animal
{
public void Test()
{
var n = this._myProtectedField; // Correct way to access, without casting.
Console.WriteLine("Test: " + n);
}
}
public abstract class Animal
{
protected int _myProtectedField = 2;
}
Erroneous output
var n = ((Animal)this)._myProtectedField // Error: not accessible like this.
Compiler error message:
Cannot access protected member 'Animal ._myProtectedField ' via a qualifier of type 'Animal'; the qualifier must be of type 'Cat' (or derived from it)
Details
Occurs in both the vscode extension and the stand alone app:
ILSpy version 10.0.1.8346+aad16c66e96eb887eb05887d6b5a9e0522637906
icsharpcode.ilspy-vscode v0.24.0
Input code
Erroneous output
Compiler error message:
Cannot access protected member 'Animal ._myProtectedField ' via a qualifier of type 'Animal'; the qualifier must be of type 'Cat' (or derived from it)
Details
Occurs in both the vscode extension and the stand alone app:
ILSpy version 10.0.1.8346+aad16c66e96eb887eb05887d6b5a9e0522637906
icsharpcode.ilspy-vscode v0.24.0