Skip to content

Commit aa73b61

Browse files
mandel-macaqueCopilotGitHub Actions Autoformatter
authored
[RGen] Emit the constructors for the protocol wrapper classes. (#23464)
Add the emittion of the default constructor for the protocol wrappers. --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: GitHub Actions Autoformatter <[email protected]>
1 parent 14efe5f commit aa73b61

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/rgen/Microsoft.Macios.Generator/Emitters/ProtocolWrapperEmitter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ class ProtocolWrapperEmitter : IClassEmitter {
2929
/// Emits the default constructors for the protocol wrapper class.
3030
/// </summary>
3131
/// <param name="bindingContext">The binding context.</param>
32+
/// <param name="wrapperClassName">The protocol wrapper class name.</param>
3233
/// <param name="classBlock">The writer for the class block.</param>
33-
void EmitDefaultConstructors (in BindingContext bindingContext, TabbedWriter<StringWriter> classBlock)
34+
void EmitDefaultConstructors (in BindingContext bindingContext, string wrapperClassName, TabbedWriter<StringWriter> classBlock)
3435
{
3536
classBlock.WriteLine ();
36-
classBlock.WriteLine ("// Implement default constructor");
37+
classBlock.AppendPreserveAttribute ();
38+
classBlock.WriteRaw (
39+
$@"public {wrapperClassName} (NativeHandle handle, bool owns)
40+
: base (handle, owns)
41+
{{
42+
}}
43+
"
44+
);
3745
}
3846

3947
/// <summary>
@@ -82,7 +90,7 @@ public bool TryEmit (in BindingContext bindingContext, [NotNullWhen (false)] out
8290
using (var classBlock = bindingContext.Builder.CreateBlock (
8391
$"internal unsafe sealed class {wrapperName} : BaseWrapper, {bindingContext.Changes.Name}",
8492
true)) {
85-
EmitDefaultConstructors (bindingContext, classBlock);
93+
EmitDefaultConstructors (bindingContext, wrapperName, classBlock);
8694
EmitProperties (bindingContext, classBlock);
8795
EmitMethods (bindingContext, classBlock);
8896
}

tests/rgen/Microsoft.Macios.Generator.Tests/Protocols/Data/ExpectedIAVAudio3DMixing.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ internal static void _SetSourceMode (this IAVAudio3DMixing self, global::AVFound
350350
internal unsafe sealed class AVAudio3DMixingWrapper : BaseWrapper, IAVAudio3DMixing
351351
{
352352

353-
// Implement default constructor
353+
[Preserve (Conditional = true)]
354+
public AVAudio3DMixingWrapper (NativeHandle handle, bool owns)
355+
: base (handle, owns)
356+
{
357+
}
354358

355359
// Implement property: Obstruction
356360

tests/rgen/Microsoft.Macios.Generator.Tests/Protocols/Data/ExpectedIAVAudioMixing.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ public virtual partial float Volume
102102
internal unsafe sealed class AVAudioMixingWrapper : BaseWrapper, IAVAudioMixing
103103
{
104104

105-
// Implement default constructor
105+
[Preserve (Conditional = true)]
106+
public AVAudioMixingWrapper (NativeHandle handle, bool owns)
107+
: base (handle, owns)
108+
{
109+
}
106110

107111
// Implement property: Obstruction
108112

0 commit comments

Comments
 (0)