Skip to content

Commit 02431b9

Browse files
authored
[.NET] Move the nfloat type to the ObjCRuntime namespace for .NET. (#13092)
Also move the NMath type from the System namespace to the ObjCRuntime namespace. Ref: #13087
1 parent 8f1e650 commit 02431b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+174
-26
lines changed

dotnet/BreakingChanges.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Breaking changes in .NET
2+
3+
## System.nfloat moved to ObjCRuntime.nfloat
4+
5+
The `nfloat` type moved from the `System` namespace to the `ObjCRuntime` namespace.
6+
7+
* Code that references the `nfloat` type might not compile unless the `ObjCRuntime` namespace is imported.
8+
9+
Fix: add `using ObjCRuntime` to the file in question.
10+
11+
* Code that references the full typename, `System.nfloat` won't compile.
12+
13+
Fix: use `ObjCRuntime.nfloat` instead.
14+
15+
## System.NMath moved to ObjCRuntime.NMath
16+
17+
The `NMath` type moved from the `System` namespace to the `ObjCRuntime` namespace.
18+
19+
* Code that uses the `NMath` type won't compile unless the `ObjCRuntime` namespace is imported.
20+
21+
Fix: add `using ObjCRuntime` to the file in question.

external/Touch.Unit

runtime/trampolines.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,11 @@
15131513
func = to_managed ? (void *) xamarin_nsnumber_to_nint : (void *) xamarin_nint_to_nsnumber;
15141514
} else if (!strcmp (fullname, "System.nuint")) {
15151515
func = to_managed ? (void *) xamarin_nsnumber_to_nuint : (void *) xamarin_nuint_to_nsnumber;
1516+
#if DOTNET
1517+
} else if (!strcmp (fullname, "ObjCRuntime.nfloat")) {
1518+
#else
15161519
} else if (!strcmp (fullname, "System.nfloat")) {
1520+
#endif
15171521
func = to_managed ? (void *) xamarin_nsnumber_to_nfloat : (void *) xamarin_nfloat_to_nsnumber;
15181522
} else if (mono_class_is_enum (managedType)) {
15191523
MonoType *baseType = mono_class_enum_basetype (managedType);

src/AppKit/Defs.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
//
2323
using System;
2424
using System.Runtime.InteropServices;
25+
26+
using ObjCRuntime;
27+
2528
namespace AppKit {
2629
[StructLayout (LayoutKind.Sequential)]
2730
public struct NSEdgeInsets {

src/AppKit/NSEvent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#if !__MACCATALYST__
22
using System;
33
using System.Diagnostics;
4+
45
using Foundation;
56
using CoreGraphics;
7+
using ObjCRuntime;
68

79
namespace AppKit {
810

src/Foundation/NSNumber.mac.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#if MONOMAC
1010

1111
using System;
12+
using ObjCRuntime;
1213

1314
namespace Foundation
1415
{

src/NativeTypes/NMath.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
// Copyright 2014 Xamarin Inc. All rights reserved.
88
//
99

10+
using System;
1011
using System.Runtime.CompilerServices;
1112

13+
#if NET
14+
namespace ObjCRuntime
15+
#else
1216
namespace System
17+
#endif
1318
{
1419
public static class NMath
1520
{

src/NativeTypes/Primitives.tt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
// Copyright 2013 Xamarin, Inc. All rights reserved.
2525
//
2626

27+
#if NET
28+
#define OBJCRUNTIME_nfloat
29+
#endif
30+
2731
<#@ template language="C#v3.5" #>
2832
<#@ import namespace="System" #>
2933
<#@ import namespace="System.Collections.Generic" #>
@@ -32,8 +36,8 @@ using System.Diagnostics;
3236
using System.Globalization;
3337
using System.Runtime.InteropServices;
3438

35-
namespace System
36-
{
39+
using ObjCRuntime;
40+
3741
<#
3842
foreach (var type in new [] {
3943
new { NSName = "nint", CilName32 = "Int32", CilName64 = "Int64", IsIntegerType = true },
@@ -56,6 +60,12 @@ namespace System
5660
binops.Add ("^");
5761
}
5862
#>
63+
#if OBJCRUNTIME_<#= type.NSName #>
64+
namespace ObjCRuntime
65+
#else
66+
namespace System
67+
#endif
68+
{
5969
[Serializable]
6070
[DebuggerDisplay ("{v,nq}")]
6171
public unsafe struct <#= type.NSName #> : IFormattable, IConvertible, IComparable, IComparable<<#= type.NSName #>>, IEquatable <<#= type.NSName #>>
@@ -429,5 +439,5 @@ namespace System
429439
Marshal.WriteIntPtr (destination, i * <#= type.NSName #>.Size, (IntPtr)source [i + startIndex]);
430440
}
431441
}
432-
<# } #>
433442
}
443+
<# } #>

src/ObjCRuntime/Registrar.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ abstract partial class Registrar {
8888
public Application App { get; protected set; }
8989
#endif
9090

91+
#if MMP || MTOUCH || BUNDLER
92+
static string NFloatTypeName { get => Driver.IsDotNet ? "ObjCRuntime.nfloat" : "System.nfloat"; }
93+
#elif NET
94+
const string NFloatTypeName = "ObjCRuntime.nfloat";
95+
#else
96+
const string NFloatTypeName = "System.nfloat";
97+
#endif
98+
9199
Dictionary<TAssembly, object> assemblies = new Dictionary<TAssembly, object> (); // Use Dictionary instead of HashSet to avoid pulling in System.Core.dll.
92100
// locking: all accesses must lock 'types'.
93101
Dictionary<TType, ObjCType> types = new Dictionary<TType, ObjCType> ();
@@ -715,10 +723,11 @@ bool IsValidToManagedTypeConversion (TType inputType, TType outputType)
715723
case "System.nuint":
716724
case "System.Single":
717725
case "System.Double":
718-
case "System.nfloat":
719726
case "System.Boolean":
720727
return true;
721728
default:
729+
if (outputTypeName == NFloatTypeName)
730+
return true;
722731
return Registrar.IsEnum (underlyingOutputType);
723732
}
724733
} else if (Registrar.Is (underlyingInputType, Foundation, "NSValue")) {
@@ -2641,12 +2650,13 @@ protected string ToSignature (TType type, ObjCMember member, ref bool success, b
26412650
return Is64Bits ? "q" : "i";
26422651
case "System.nuint":
26432652
return Is64Bits ? "Q" : "I";
2644-
case "System.nfloat":
2645-
return Is64Bits ? "d" : "f";
26462653
case "System.DateTime":
26472654
throw CreateException (4102, member, Errors.MT4102, "System.DateTime", "Foundation.NSDate", member.FullName);
26482655
}
26492656

2657+
if (typeFullName == NFloatTypeName)
2658+
return Is64Bits ? "d" : "f";
2659+
26502660
if (Is (type, ObjCRuntime, "Selector"))
26512661
return ":";
26522662

0 commit comments

Comments
 (0)