Created
December 7, 2017 23:00
-
-
Save colinjneville/ba7d8ac13c84e135f19df500d1879e20 to your computer and use it in GitHub Desktop.
Mono CS1540 test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
static class M { | |
static void Main() | |
{ | |
B b = new B(); | |
// Outside the scope of the B members, the A members are used | |
var x = b.Property; | |
b.Method(); | |
b.Field = true; | |
C c = new C(); | |
c.G(c); | |
} | |
} | |
public class A { | |
public bool Property { | |
get { | |
Console.WriteLine("Public Property"); | |
return true; | |
} | |
} | |
public bool Method() { | |
Console.WriteLine("Public Method"); | |
return true; | |
} | |
public bool Field; | |
} | |
public class B : A { | |
protected new bool Property { | |
get { | |
Console.WriteLine("Protected Property"); | |
return true; | |
} | |
} | |
protected new bool Method() { | |
Console.WriteLine("Protected Method"); | |
return true; | |
} | |
protected new bool Field; | |
} | |
public class C : B { | |
public void G(B b) { | |
// error CS1540: Cannot access protected member `B.Property' via a qualifier of type `B'. The qualifier must be of type `M.C' or derived from it | |
var x = b.Property; | |
// error CS1540: Cannot access protected member `B.Field' via a qualifier of type `B'. The qualifier must be of type `M.C' or derived from it | |
b.Field = true; | |
// Method call compiles without error | |
b.Method(); | |
// Workaround: cast to base class with public accessibility | |
var y = ((A)b).Property; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment