Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit b991bb8

Browse files
authored
[generator] Revert change to use auto-properties in EventArgs classes (#736)
In ee7afee, properties in generated EventArgs classes were changed from regular properties: int param1; public int Param1 { get { return param1; } } to instead emit auto-properties: public int Param1 { get; } However, this is technically a source breaking change, since users could have hand written code that references the backing field. Although the usage is likely rare, we have decided to revert the auto-property change for compatibility reasons.
1 parent ee50d89 commit b991bb8

3 files changed

Lines changed: 90 additions & 34 deletions

File tree

‎tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteDuplicateInterfaceEventArgs.txt‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,37 @@ internal partial class AnimatorListenerInvoker : global::Java.Lang.Object, Anima
123123

124124
// event args for java.code.AnimatorListener.OnAnimationEnd
125125
public partial class AnimationEndEventArgs : global::System.EventArgs {
126+
bool handled;
127+
128+
public bool Handled {
129+
get { return handled; }
130+
set { handled = value; }
131+
}
132+
126133
public AnimationEndEventArgs (bool handled, int param1)
127134
{
128-
this.Handled = handled;
129-
this.Param1 = param1;
135+
this.handled = handled;
136+
this.param1 = param1;
137+
}
138+
139+
int param1;
140+
141+
public int Param1 {
142+
get { return param1; }
130143
}
131144

132145
public AnimationEndEventArgs (bool handled, int param1, int param2)
133146
{
134-
this.Handled = handled;
135-
this.Param1 = param1;
136-
this.Param2 = param2;
147+
this.handled = handled;
148+
this.param1 = param1;
149+
this.param2 = param2;
137150
}
138151

139-
public bool Handled { get; set; }
152+
int param2;
140153

141-
public int Param1 { get; private set; }
142-
143-
public int Param2 { get; private set; }
154+
public int Param2 {
155+
get { return param2; }
156+
}
144157

145158
}
146159

‎tests/generator-Tests/expected.ji/GenericArguments/Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,42 @@ public unsafe void OnEvent (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDr
123123
publicpartialclassExoMediaDrmOnEventEventArgs:global::System.EventArgs{
124124
publicExoMediaDrmOnEventEventArgs(global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmp0,byte[]p1,intp2,intp3,byte[]p4)
125125
{
126-
this.P0=p0;
127-
this.P1=p1;
128-
this.P2=p2;
129-
this.P3=p3;
130-
this.P4=p4;
126+
this.p0=p0;
127+
this.p1=p1;
128+
this.p2=p2;
129+
this.p3=p3;
130+
this.p4=p4;
131131
}
132132

133-
publicglobal::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmP0{get;privateset;}
133+
global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmp0;
134134

135-
publicbyte[]P1{get;privateset;}
135+
publicglobal::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmP0{
136+
get{returnp0;}
137+
}
138+
139+
byte[]p1;
140+
141+
publicbyte[]P1{
142+
get{returnp1;}
143+
}
144+
145+
intp2;
136146

137-
publicintP2{get;privateset;}
147+
publicintP2{
148+
get{returnp2;}
149+
}
150+
151+
intp3;
138152

139-
publicintP3{get;privateset;}
153+
publicintP3{
154+
get{returnp3;}
155+
}
140156

141-
publicbyte[]P4{get;privateset;}
157+
byte[]p4;
158+
159+
publicbyte[]P4{
160+
get{returnp4;}
161+
}
142162

143163
}
144164

‎tools/generator/SourceWriters/InterfaceEventArgsClass.cs‎

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@ public InterfaceEventArgsClass (InterfaceGen iface, Method method)
1818
IsPublic=true;
1919
IsPartial=true;
2020

21+
UsePriorityOrder=true;
22+
2123
Comments.Add($"// event args for {iface.JavaName}.{method.JavaName}");
2224

23-
// Add: public bool Handled { get; set; }
2425
if(method.IsEventHandlerWithHandledProperty)
25-
Properties.Add(newPropertyWriter{
26-
Name="Handled",
27-
PropertyType=TypeReferenceWriter.Bool,
28-
IsPublic=true,
29-
HasGet=true,
30-
HasSet=true,
31-
IsAutoProperty=true
32-
});
26+
Properties.Add(newHandledProperty());
3327
}
3428

3529
publicvoidAddMembersFromMethod(InterfaceGeniface,Methodmethod,CodeGenerationOptionsopt)
@@ -47,15 +41,15 @@ void AddConstructor (InterfaceGen iface, Method method, CodeGenerationOptions op
4741

4842
if(method.IsEventHandlerWithHandledProperty){
4943
ctor.Parameters.Add(newMethodParameterWriter("handled",TypeReferenceWriter.Bool));
50-
ctor.Body.Add("this.Handled = handled;");
44+
ctor.Body.Add("this.handled = handled;");
5145
}
5246

5347
foreach(varpinmethod.Parameters){
5448
if(p.IsSender)
5549
continue;
5650

5751
ctor.Parameters.Add(newMethodParameterWriter(p.Name,newTypeReferenceWriter(opt.GetTypeReferenceName(p))));
58-
ctor.Body.Add($"this.{p.PropertyName} = {opt.GetSafeIdentifier(p.Name)};");
52+
ctor.Body.Add($"this.{opt.GetSafeIdentifier(p.Name)} = {opt.GetSafeIdentifier(p.Name)};");
5953
}
6054

6155
Constructors.Add(ctor);
@@ -71,18 +65,47 @@ void AddProperties (Method method, CodeGenerationOptions opt)
7165
if(Properties.Any(prop =>prop.Name==p.PropertyName))
7266
continue;
7367

68+
Fields.Add(newFieldWriter{
69+
Name=opt.GetSafeIdentifier(p.Name),
70+
Type=newTypeReferenceWriter(opt.GetTypeReferenceName(p))
71+
});
72+
7473
varprop=newPropertyWriter{
7574
Name=p.PropertyName,
7675
PropertyType=newTypeReferenceWriter(opt.GetTypeReferenceName(p)),
7776
IsPublic=true,
78-
HasGet=true,
79-
HasSet=true,
80-
IsAutoProperty=true,
81-
AutoSetterVisibility=Visibility.Private
77+
HasGet=true
8278
};
8379

80+
prop.GetBody.Add($"return {opt.GetSafeIdentifier(p.Name)};");
81+
8482
Properties.Add(prop);
8583
}
8684
}
8785
}
86+
87+
publicclassHandledProperty:PropertyWriter
88+
{
89+
publicHandledProperty()
90+
{
91+
Name="Handled";
92+
PropertyType=TypeReferenceWriter.Bool;
93+
94+
IsPublic=true;
95+
96+
HasGet=true;
97+
GetBody.Add("return handled;");
98+
99+
HasSet=true;
100+
SetBody.Add("handled = value;");
101+
}
102+
103+
publicoverridevoidWrite(CodeWriterwriter)
104+
{
105+
writer.WriteLine("bool handled;");
106+
writer.WriteLine();
107+
108+
base.Write(writer);
109+
}
110+
}
88111
}

0 commit comments

Comments
 (0)