public override bool Define (TypeContainer parent) { EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName; if (!DoDefine (parent)) return false; if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){ Report.Error (74, Location, "'" + parent.Name + "." + Name + "': abstract event can not have an initializer"); return false; } if (!MemberType.IsSubclassOf (TypeManager.delegate_type)) { Report.Error (66, Location, "'" + parent.Name + "." + Name + "' : event must be of a delegate type"); return false; } Type [] parameter_types = new Type [1]; parameter_types [0] = MemberType; Parameter [] parms = new Parameter [1]; parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null); InternalParameters ip = new InternalParameters ( parent, new Parameters (parms, null, Location)); if (!CheckBase (parent)) return false; // // Now define the accessors // AddData = new MethodData (this, "add", TypeManager.void_type, parameter_types, ip, CallingConventions.Standard, (Add != null) ? Add.OptAttributes : null, ModFlags, flags, false); if (!AddData.Define (parent)) return false; AddBuilder = AddData.MethodBuilder; AddBuilder.DefineParameter (1, ParameterAttributes.None, "value"); RemoveData = new MethodData (this, "remove", TypeManager.void_type, parameter_types, ip, CallingConventions.Standard, (Remove != null) ? Remove.OptAttributes : null, ModFlags, flags, false); if (!RemoveData.Define (parent)) return false; RemoveBuilder = RemoveData.MethodBuilder; RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value"); if (!IsExplicitImpl){ EventBuilder = new MyEventBuilder (this, parent.TypeBuilder, Name, e_attr, MemberType); if (Add == null && Remove == null) { FieldBuilder = parent.TypeBuilder.DefineField ( Name, MemberType, FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0)); TypeManager.RegisterPrivateFieldOfEvent ( (EventInfo) EventBuilder, FieldBuilder); TypeManager.RegisterFieldBase (FieldBuilder, this); } EventBuilder.SetAddOnMethod (AddBuilder); EventBuilder.SetRemoveOnMethod (RemoveBuilder); if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) { Report.Error (111, Location, "Class `" + parent.Name + "' already contains a definition for the event `" + Name + "'"); return false; } } return true; }
public override bool Define () { if (!base.Define ()) return false; if (!TypeManager.IsDelegateType (MemberType)) { Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ()); } parameters = ParametersCompiled.CreateFullyResolved ( new Parameter (null, "value", Parameter.Modifier.NONE, null, Location), MemberType); if (!CheckBase ()) return false; if (TypeManager.delegate_combine_delegate_delegate == null) { TypeManager.delegate_combine_delegate_delegate = TypeManager.GetPredefinedMethod ( TypeManager.delegate_type, "Combine", Location, TypeManager.delegate_type, TypeManager.delegate_type); } if (TypeManager.delegate_remove_delegate_delegate == null) { TypeManager.delegate_remove_delegate_delegate = TypeManager.GetPredefinedMethod ( TypeManager.delegate_type, "Remove", Location, TypeManager.delegate_type, TypeManager.delegate_type); } // // Now define the accessors // AddBuilder = Add.Define (Parent); if (AddBuilder == null) return false; RemoveBuilder = Remove.Define (Parent); if (RemoveBuilder == null) return false; EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, EventAttributes.None, MemberType); EventBuilder.SetAddOnMethod (AddBuilder); EventBuilder.SetRemoveOnMethod (RemoveBuilder); Parent.MemberCache.AddMember (EventBuilder, this); Parent.MemberCache.AddMember (AddBuilder, Add); Parent.MemberCache.AddMember (RemoveBuilder, Remove); return true; }