+
+ MemberLookupFailed (ec, qualifier_type, queried_type, name, null, loc);
+ return null;
+ }
+
+ public static void MemberLookupFailed (EmitContext ec, Type qualifier_type,
+ Type queried_type, string name,
+ string class_name, Location loc)
+ {
+ object lookup = TypeManager.MemberLookup (queried_type, null, queried_type,
+ AllMemberTypes, AllBindingFlags |
+ BindingFlags.NonPublic, name);
+
+ if (lookup == null) {
+ if (class_name != null)
+ Report.Error (103, loc, "The name `" + name + "' could not be " +
+ "found in `" + class_name + "'");
+ else
+ Report.Error (
+ 117, loc, "`" + queried_type + "' does not contain a " +
+ "definition for `" + name + "'");
+ return;
+ }
+
+ if ((qualifier_type != null) && (qualifier_type != ec.ContainerType) &&
+ ec.ContainerType.IsSubclassOf (qualifier_type)) {
+ // Although a derived class can access protected members of
+ // its base class it cannot do so through an instance of the
+ // base class (CS1540). If the qualifier_type is a parent of the
+ // ec.ContainerType and the lookup succeeds with the latter one,
+ // then we are in this situation.
+
+ lookup = TypeManager.MemberLookup (
+ ec.ContainerType, ec.ContainerType, ec.ContainerType,
+ AllMemberTypes, AllBindingFlags, name);
+
+ if (lookup != null) {
+ Report.Error (
+ 1540, loc, "Cannot access protected member `" +
+ TypeManager.CSharpName (qualifier_type) + "." +
+ name + "' " + "via a qualifier of type `" +
+ TypeManager.CSharpName (qualifier_type) + "'; the " +
+ "qualifier must be of type `" +
+ TypeManager.CSharpName (ec.ContainerType) + "' " +
+ "(or derived from it)");
+ return;
+ }
+ }
+
+ if (qualifier_type != null)