diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteDuplicateInterfaceEventArgs.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteDuplicateInterfaceEventArgs.txt index cce5a205d..57a6aed74 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteDuplicateInterfaceEventArgs.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteDuplicateInterfaceEventArgs.txt @@ -123,24 +123,37 @@ internal partial class AnimatorListenerInvoker : global::Java.Lang.Object, Anima // event args for java.code.AnimatorListener.OnAnimationEnd public partial class AnimationEndEventArgs : global::System.EventArgs { + bool handled; + + public bool Handled { + get { return handled; } + set { handled = value; } + } + public AnimationEndEventArgs (bool handled, int param1) { - this.Handled = handled; - this.Param1 = param1; + this.handled = handled; + this.param1 = param1; + } + + int param1; + + public int Param1 { + get { return param1; } } public AnimationEndEventArgs (bool handled, int param1, int param2) { - this.Handled = handled; - this.Param1 = param1; - this.Param2 = param2; + this.handled = handled; + this.param1 = param1; + this.param2 = param2; } - public bool Handled { get; set; } + int param2; - public int Param1 { get; private set; } - - public int Param2 { get; private set; } + public int Param2 { + get { return param2; } + } } diff --git a/tests/generator-Tests/expected.ji/GenericArguments/Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs b/tests/generator-Tests/expected.ji/GenericArguments/Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs index 202929cd4..4928e0dcc 100644 --- a/tests/generator-Tests/expected.ji/GenericArguments/Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs +++ b/tests/generator-Tests/expected.ji/GenericArguments/Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs @@ -123,22 +123,42 @@ public unsafe void OnEvent (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDr public partial class ExoMediaDrmOnEventEventArgs : global::System.EventArgs { public ExoMediaDrmOnEventEventArgs (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm p0, byte[] p1, int p2, int p3, byte[] p4) { - this.P0 = p0; - this.P1 = p1; - this.P2 = p2; - this.P3 = p3; - this.P4 = p4; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; } - public global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm P0 { get; private set; } + global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm p0; - public byte[] P1 { get; private set; } + public global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm P0 { + get { return p0; } + } + + byte[] p1; + + public byte[] P1 { + get { return p1; } + } + + int p2; - public int P2 { get; private set; } + public int P2 { + get { return p2; } + } + + int p3; - public int P3 { get; private set; } + public int P3 { + get { return p3; } + } - public byte[] P4 { get; private set; } + byte[] p4; + + public byte[] P4 { + get { return p4; } + } } diff --git a/tools/generator/SourceWriters/InterfaceEventArgsClass.cs b/tools/generator/SourceWriters/InterfaceEventArgsClass.cs index 3e1dbda38..5e0b9dee9 100644 --- a/tools/generator/SourceWriters/InterfaceEventArgsClass.cs +++ b/tools/generator/SourceWriters/InterfaceEventArgsClass.cs @@ -18,18 +18,12 @@ public InterfaceEventArgsClass (InterfaceGen iface, Method method) IsPublic = true; IsPartial = true; + UsePriorityOrder = true; + Comments.Add ($"// event args for {iface.JavaName}.{method.JavaName}"); - // Add: public bool Handled { get; set; } if (method.IsEventHandlerWithHandledProperty) - Properties.Add (new PropertyWriter { - Name = "Handled", - PropertyType = TypeReferenceWriter.Bool, - IsPublic = true, - HasGet = true, - HasSet = true, - IsAutoProperty = true - }); + Properties.Add (new HandledProperty ()); } public void AddMembersFromMethod (InterfaceGen iface, Method method, CodeGenerationOptions opt) @@ -47,7 +41,7 @@ void AddConstructor (InterfaceGen iface, Method method, CodeGenerationOptions op if (method.IsEventHandlerWithHandledProperty) { ctor.Parameters.Add (new MethodParameterWriter ("handled", TypeReferenceWriter.Bool)); - ctor.Body.Add ("this.Handled = handled;"); + ctor.Body.Add ("this.handled = handled;"); } foreach (var p in method.Parameters) { @@ -55,7 +49,7 @@ void AddConstructor (InterfaceGen iface, Method method, CodeGenerationOptions op continue; ctor.Parameters.Add (new MethodParameterWriter (p.Name, new TypeReferenceWriter (opt.GetTypeReferenceName (p)))); - ctor.Body.Add ($"this.{p.PropertyName} = {opt.GetSafeIdentifier (p.Name)};"); + ctor.Body.Add ($"this.{opt.GetSafeIdentifier (p.Name)} = {opt.GetSafeIdentifier (p.Name)};"); } Constructors.Add (ctor); @@ -71,18 +65,47 @@ void AddProperties (Method method, CodeGenerationOptions opt) if (Properties.Any (prop => prop.Name == p.PropertyName)) continue; + Fields.Add (new FieldWriter { + Name = opt.GetSafeIdentifier (p.Name), + Type = new TypeReferenceWriter (opt.GetTypeReferenceName (p)) + }); + var prop = new PropertyWriter { Name = p.PropertyName, PropertyType = new TypeReferenceWriter (opt.GetTypeReferenceName (p)), IsPublic = true, - HasGet = true, - HasSet = true, - IsAutoProperty = true, - AutoSetterVisibility = Visibility.Private + HasGet = true }; + prop.GetBody.Add ($"return {opt.GetSafeIdentifier (p.Name)};"); + Properties.Add (prop); } } } + + public class HandledProperty : PropertyWriter + { + public HandledProperty () + { + Name = "Handled"; + PropertyType = TypeReferenceWriter.Bool; + + IsPublic = true; + + HasGet = true; + GetBody.Add ("return handled;"); + + HasSet = true; + SetBody.Add ("handled = value;"); + } + + public override void Write (CodeWriter writer) + { + writer.WriteLine ("bool handled;"); + writer.WriteLine (); + + base.Write (writer); + } + } }