public override void Write(CodeWriter writer)
        {
            if (method.EventName != string.Empty)
            {
                writer.WriteLine("#pragma warning disable 0649");
                writer.WriteLine($"public {iface.GetEventDelegateName (method)}{opt.NullableOperator} {method_spec}Handler;");
                writer.WriteLine("#pragma warning restore 0649");
                writer.WriteLine();
            }

            base.Write(writer);
        }
예제 #2
0
        void AddInterfaceEventHandler(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            if (!iface.IsListener)
            {
                return;
            }

            foreach (var method in iface.Methods.Where(m => m.EventName != string.Empty))
            {
                if (method.RetVal.IsVoid || method.IsEventHandlerWithHandledProperty)
                {
                    if (!method.IsSimpleEventHandler || method.IsEventHandlerWithHandledProperty)
                    {
                        var event_args_class = post_sibling_types.OfType <InterfaceEventArgsClass> ().SingleOrDefault(c => c.Name == iface.GetArgsName(method));

                        // Check if there's an existing EventArgs class to add to
                        if (event_args_class is null)
                        {
                            event_args_class = new InterfaceEventArgsClass(iface, method);
                            post_sibling_types.Add(event_args_class);
                        }

                        event_args_class.AddMembersFromMethod(iface, method, opt);
                    }
                }
                else
                {
                    var del = new DelegateWriter {
                        Name     = iface.GetEventDelegateName(method),
                        Type     = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal)),
                        IsPublic = true
                    };

                    SourceWriterExtensions.AddMethodParameters(del, method.Parameters, opt);

                    post_sibling_types.Add(del);
                }
            }

            post_sibling_types.Add(new InterfaceEventHandlerImplClass(iface, opt, context));
        }