Skip to content

Commit 200c743

Browse files
committed
Revert "[generator] Disable [SupportedOSPlatform] until .NET 5/6. (#781)"
This reverts commit 00862ad.
1 parent 131c149 commit 200c743

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,18 @@ class XAJavaInteropCodeGeneratorTests : CodeGeneratorTests
276276
{
277277
protected override CodeGenerationTarget Target => CodeGenerationTarget.XAJavaInterop1;
278278

279+
[Test]
280+
public void SupportedOSPlatform ()
281+
{
282+
var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
283+
klass.ApiAvailableSince = 30;
279284

280-
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
281-
//[Test]
282-
//public void SupportedOSPlatform ()
283-
//{
284-
// var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
285-
// klass.ApiAvailableSince = 30;
286-
287-
// generator.Context.ContextTypes.Push (klass);
288-
// generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
289-
// generator.Context.ContextTypes.Pop ();
285+
generator.Context.ContextTypes.Push (klass);
286+
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
287+
generator.Context.ContextTypes.Pop ();
290288

291-
// StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
292-
//}
289+
StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
290+
}
293291
}
294292

295293
[TestFixture]

tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,20 @@ public void Generate (CodeGenerationOptions opt, GenerationInfo gen_info)
3232
foreach (var jni in opt.GetJniMarshalDelegates ())
3333
sw.WriteLine ($"delegate {FromJniType (jni[jni.Length - 1])} {jni} (IntPtr jnienv, IntPtr klass{GetDelegateParameters (jni)});");
3434

35-
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
3635
// [SupportedOSPlatform] only exists in .NET 5.0+, so we need to generate a
3736
// dummy one so earlier frameworks can compile.
38-
//if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) {
39-
// sw.WriteLine ("#if !NET");
40-
// sw.WriteLine ("namespace System.Runtime.Versioning {");
41-
// sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]");
42-
// sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]");
43-
// sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {");
44-
// sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }");
45-
// sw.WriteLine (" }");
46-
// sw.WriteLine ("}");
47-
// sw.WriteLine ("#endif");
48-
// sw.WriteLine ("");
49-
//}
37+
if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) {
38+
sw.WriteLine ("#if !NET");
39+
sw.WriteLine ("namespace System.Runtime.Versioning {");
40+
sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]");
41+
sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]");
42+
sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {");
43+
sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }");
44+
sw.WriteLine (" }");
45+
sw.WriteLine ("}");
46+
sw.WriteLine ("#endif");
47+
sw.WriteLine ("");
48+
}
5049
}
5150
}
5251

tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class SupportedOSPlatformAttr : AttributeWriter
1515

1616
public override void WriteAttribute (CodeWriter writer)
1717
{
18-
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
19-
//writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]");
18+
writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]");
2019
}
2120
}
2221
}

0 commit comments

Comments
 (0)