public override bool Define (TypeContainer parent) { Type t = parent.ResolveType (Type, false, Location); if (t == null) return false; if (!parent.AsAccessible (t, ModFlags)) { Report.Error (52, Location, "Inconsistent accessibility: field type `" + TypeManager.CSharpName (t) + "' is less " + "accessible than field `" + Name + "'"); return false; } if (RootContext.WarningLevel > 1){ Type ptype = parent.TypeBuilder.BaseType; // ptype is only null for System.Object while compiling corlib. if (ptype != null){ TypeContainer.FindMembers ( ptype, MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, System.Type.FilterName, Name); } } if ((ModFlags & Modifiers.VOLATILE) != 0){ if (!t.IsClass){ Type vt = t; if (TypeManager.IsEnumType (vt)) vt = TypeManager.EnumToUnderlying (t); if (!((vt == TypeManager.bool_type) || (vt == TypeManager.sbyte_type) || (vt == TypeManager.byte_type) || (vt == TypeManager.short_type) || (vt == TypeManager.ushort_type) || (vt == TypeManager.int32_type) || (vt == TypeManager.uint32_type) || (vt == TypeManager.char_type) || (vt == TypeManager.float_type))){ Report.Error ( 677, Location, parent.MakeName (Name) + " A volatile field can not be of type `" + TypeManager.CSharpName (vt) + "'"); return false; } } } FieldAttributes fa = Modifiers.FieldAttr (ModFlags); if (parent is Struct && ((fa & FieldAttributes.Static) == 0) && t == parent.TypeBuilder && !TypeManager.IsBuiltinType (t)){ Report.Error (523, Location, "Struct member `" + parent.Name + "." + Name + "' causes a cycle in the structure layout"); return false; } FieldBuilder = parent.TypeBuilder.DefineField ( Name, t, Modifiers.FieldAttr (ModFlags)); TypeManager.RegisterFieldBase (FieldBuilder, this); return true; }
// // Checks our base implementation if any // protected override bool CheckBase (TypeContainer parent) { // Check whether arguments were correct. if (!DoDefineParameters (parent)) return false; if (IsExplicitImpl) return true; string report_name; MethodSignature ms, base_ms; if (this is Indexer) { string name, base_name; report_name = "this"; name = TypeManager.IndexerPropertyName (parent.TypeBuilder); ms = new MethodSignature (name, null, ParameterTypes); base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType); base_ms = new MethodSignature (base_name, null, ParameterTypes); } else { report_name = Name; ms = base_ms = new MethodSignature (Name, null, ParameterTypes); } // // Verify if the parent has a type with the same name, and then // check whether we have to create a new slot for it or not. // Type ptype = parent.TypeBuilder.BaseType; // ptype is only null for System.Object while compiling corlib. if (ptype == null) { if ((ModFlags & Modifiers.NEW) != 0) WarningNotHiding (parent); return true; } MemberList props_this; props_this = TypeContainer.FindMembers ( parent.TypeBuilder, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly, MethodSignature.method_signature_filter, ms); if (props_this.Count > 0) { Report.Error (111, Location, "Class `" + parent.Name + "' " + "already defines a member called `" + report_name + "' " + "with the same parameter types"); return false; } MemberList mi_props; mi_props = TypeContainer.FindMembers ( ptype, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, MethodSignature.inheritable_method_signature_filter, base_ms); if (mi_props.Count > 0){ PropertyInfo parent_property = (PropertyInfo) mi_props [0]; string name = parent_property.DeclaringType.Name + "." + parent_property.Name; MethodInfo get, set, parent_method; get = parent_property.GetGetMethod (true); set = parent_property.GetSetMethod (true); if (get != null) parent_method = get; else if (set != null) parent_method = set; else throw new Exception ("Internal error!"); if (!CheckMethodAgainstBase (parent, flags, parent_method, name)) return false; if ((ModFlags & Modifiers.NEW) == 0) { Type parent_type = TypeManager.TypeToCoreType ( parent_property.PropertyType); if (parent_type != MemberType) { Report.Error ( 508, Location, parent.MakeName (Name) + ": cannot " + "change return type when overriding " + "inherited member " + name); return false; } } } else { if ((ModFlags & Modifiers.NEW) != 0) WarningNotHiding (parent); if ((ModFlags & Modifiers.OVERRIDE) != 0){ if (this is Indexer) Report.Error (115, Location, parent.MakeName (Name) + " no suitable indexers found to override"); else Report.Error (115, Location, parent.MakeName (Name) + " no suitable properties found to override"); return false; } } return true; }
// // Checks our base implementation if any // protected override bool CheckBase (TypeContainer parent) { // Check whether arguments were correct. if (!DoDefineParameters (parent)) return false; MethodSignature ms = new MethodSignature (Name, null, ParameterTypes); if (IsOperator) { flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig; } else { MemberList mi_this; mi_this = TypeContainer.FindMembers ( parent.TypeBuilder, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly, MethodSignature.method_signature_filter, ms); if (mi_this.Count > 0) { Report.Error (111, Location, "Class `" + parent.Name + "' " + "already defines a member called `" + Name + "' " + "with the same parameter types"); return false; } } // // Verify if the parent has a type with the same name, and then // check whether we have to create a new slot for it or not. // Type ptype = parent.TypeBuilder.BaseType; // ptype is only null for System.Object while compiling corlib. if (ptype != null){ MemberList mi, mi_static, mi_instance; mi_instance = TypeContainer.FindMembers ( ptype, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, MethodSignature.inheritable_method_signature_filter, ms); if (mi_instance.Count > 0){ mi = mi_instance; } else { mi_static = TypeContainer.FindMembers ( ptype, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, MethodSignature.inheritable_method_signature_filter, ms); if (mi_static.Count > 0) mi = mi_static; else mi = null; } if (mi != null && mi.Count > 0){ parent_method = (MethodInfo) mi [0]; string name = parent_method.DeclaringType.Name + "." + parent_method.Name; if (!CheckMethodAgainstBase (parent, flags, parent_method, name)) return false; if ((ModFlags & Modifiers.NEW) == 0) { Type parent_ret = TypeManager.TypeToCoreType ( parent_method.ReturnType); if (parent_ret != MemberType) { Report.Error ( 508, Location, parent.MakeName (Name) + ": cannot " + "change return type when overriding " + "inherited member " + name); return false; } } } else { if ((ModFlags & Modifiers.NEW) != 0) WarningNotHiding (parent); if ((ModFlags & Modifiers.OVERRIDE) != 0){ Report.Error (115, Location, parent.MakeName (Name) + " no suitable methods found to override"); } } } else if ((ModFlags & Modifiers.NEW) != 0) WarningNotHiding (parent); return true; }