From e01f115ab04e803f114eba785a02506867a153f1 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jan 2025 11:44:59 +0100 Subject: [PATCH 1/2] [Foundation] Remove NET conditions from some files. --- src/AppKit/Enums.cs | 16 --- src/Foundation/Compat.cs | 26 +---- src/Foundation/DictionaryContainer.cs | 10 -- src/Foundation/Enum.cs | 30 ------ src/Foundation/LinkerSafeAttribute.cs | 2 - src/Foundation/ModelAttribute.cs | 3 - src/Foundation/MonoTouchException.cs | 72 ------------- src/Foundation/NSArray.cs | 14 --- src/Foundation/NSArray_1.cs | 20 ---- src/Foundation/NSAttributedString.cs | 2 - src/Foundation/NSObject2.cs | 141 +------------------------- src/Foundation/NSUrlSessionHandler.cs | 58 +---------- src/frameworks.sources | 1 - 13 files changed, 7 insertions(+), 388 deletions(-) delete mode 100644 src/Foundation/MonoTouchException.cs diff --git a/src/AppKit/Enums.cs b/src/AppKit/Enums.cs index b178cae88586..9acf4b72db68 100644 --- a/src/AppKit/Enums.cs +++ b/src/AppKit/Enums.cs @@ -1439,22 +1439,6 @@ public enum NSPasteboardReadingOptions : ulong { AsKeyedArchive = 4, } -#if !NET && MONOMAC // Use the one in Foundation instead, only keep this in macOS until .NET. - [Native] - public enum NSUnderlineStyle : long { - None = 0x00, - Single = 0x01, - Thick = 0x02, - Double = 0x09, - PatternSolid = 0x0000, - PatternDot = 0x0100, - PatternDash = 0x0200, - PatternDashDot = 0x0300, - PatternDashDotDot = 0x0400, - ByWord = 0x8000, - } -#endif - // Convenience enum, untyped in ObjC [NoMacCatalyst] public enum NSUnderlinePattern : int { diff --git a/src/Foundation/Compat.cs b/src/Foundation/Compat.cs index d71b94b5c7d0..4173975d8cb4 100644 --- a/src/Foundation/Compat.cs +++ b/src/Foundation/Compat.cs @@ -1,5 +1,5 @@ // -// Compat.cs: Stuff we won't provide in Xamarin.iOS.dll or newer XAMCORE_* profiles +// Compat.cs: Stuff we won't provide in newer XAMCORE_* profiles // // Authors: // Sebastien Pouliot @@ -12,30 +12,6 @@ using ObjCRuntime; namespace Foundation { - -#if !NET -#if MONOMAC - public partial class NSError { - - // removed in Xcode 11 GM - [Obsolete ("This API has been removed.")] - public static NSError GetFileProviderErrorForOutOfDateItem (FileProvider.INSFileProviderItem updatedVersion) - { - return null; - } - } -#endif - - public partial class NSUserActivity { - - [Obsolete ("Use the constructor that allows you to set an activity type.")] - public NSUserActivity () - : this (String.Empty) - { - } - } -#endif // !NET - #if !XAMCORE_5_0 #if __IOS__ && !__MACCATALYST__ public partial class NSUrlConnection { diff --git a/src/Foundation/DictionaryContainer.cs b/src/Foundation/DictionaryContainer.cs index 363501052412..257afc5d5ac7 100644 --- a/src/Foundation/DictionaryContainer.cs +++ b/src/Foundation/DictionaryContainer.cs @@ -43,20 +43,14 @@ using UIKit; #endif -#if !NET -using NativeHandle = System.IntPtr; -#endif - #nullable enable namespace Foundation { -#if NET [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("maccatalyst")] [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("tvos")] -#endif public abstract class DictionaryContainer { #if !COREBUILD protected DictionaryContainer () @@ -247,11 +241,7 @@ protected DictionaryContainer (NSDictionary? dictionary) return value as NSDictionary; } -#if NET protected T? GetStrongDictionary<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T> (NSString key) -#else - protected T? GetStrongDictionary (NSString key) -#endif where T : DictionaryContainer { return GetStrongDictionary (key, dict => diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index 82ae2939c54f..1132c4afd283 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -77,14 +77,9 @@ public enum NSUrlCredentialPersistence : ulong { #if MONOMAC -#if !NET - [Native] - public enum NSBundleExecutableArchitecture : long { -#else /// The bundle's architecture. [NoiOS][NoTV][NoMacCatalyst] public enum NSBundleExecutableArchitecture { -#endif I386 = 0x00000007, PPC = 0x00000012, X86_64 = 0x01000007, @@ -252,10 +247,6 @@ public enum NSCalendarUnit : ulong { public enum NSDataReadingOptions : ulong { Mapped = 1 << 0, Uncached = 1 << 1, -#if !NET - [Obsolete ("This option is unavailable.")] - Coordinated = 1 << 2, -#endif MappedAlways = 1 << 3, } @@ -592,10 +583,6 @@ public enum NSVolumeEnumerationOptions : ulong { [Flags] [Native] public enum NSDirectoryEnumerationOptions : ulong { -#if !NET - [Obsolete ("Use 'None' instead.")] - SkipsNone = 0, -#endif None = 0, SkipsSubdirectoryDescendants = 1 << 0, SkipsPackageDescendants = 1 << 1, @@ -808,10 +795,6 @@ public enum NSJsonReadingOptions : ulong { Json5Allowed = 8, [iOS (15, 0), TV (15, 0), MacCatalyst (15, 0)] TopLevelDictionaryAssumed = 16, -#if !NET - [Obsolete ("Use 'FragmentsAllowed. instead.")] - AllowFragments = FragmentsAllowed, -#endif } [Flags] @@ -889,7 +872,6 @@ public enum NSAttributedStringEnumeration : ulong { LongestEffectiveRangeNotRequired = 1 << 20, } -#if NET || !MONOMAC // macOS has defined this in AppKit as well, but starting with .NET we're going // to use this one only. [Native] @@ -905,7 +887,6 @@ public enum NSUnderlineStyle : long { PatternDashDotDot = 0x0400, ByWord = 0x8000, } -#endif // There's an AppKit.NSWritingDirection, which is deprecated. // There's also an UIKit.UITextWritingDirection, which is deprecated too. @@ -977,17 +958,6 @@ public enum NSLigatureType : long { All, } -#if !NET - [Flags] - [Native] - public enum NSDateComponentsWrappingBehavior : ulong { - None = 0, - WrapCalendarComponents = 1 << 0, - - // Did not add the new enums here, we moved them elsewhere, and provided overloads. - } -#endif - [Flags] [Native] public enum NSCalendarOptions : ulong { diff --git a/src/Foundation/LinkerSafeAttribute.cs b/src/Foundation/LinkerSafeAttribute.cs index f2260de1d86c..41e3b493a8d5 100644 --- a/src/Foundation/LinkerSafeAttribute.cs +++ b/src/Foundation/LinkerSafeAttribute.cs @@ -29,10 +29,8 @@ namespace Foundation { -#if NET [Obsolete ("Replace with '[assembly: System.Reflection.AssemblyMetadata (\"IsTrimmable\", \"True\")]'.")] [EditorBrowsable (EditorBrowsableState.Never)] -#endif [AttributeUsage (AttributeTargets.Assembly)] public sealed class LinkerSafeAttribute : Attribute { diff --git a/src/Foundation/ModelAttribute.cs b/src/Foundation/ModelAttribute.cs index a00b71e67142..a7b0572cad53 100644 --- a/src/Foundation/ModelAttribute.cs +++ b/src/Foundation/ModelAttribute.cs @@ -32,8 +32,5 @@ public sealed class ModelAttribute : Attribute { public ModelAttribute () { } public string? Name { get; set; } -#if !NET - public bool AutoGeneratedName { get; set; } -#endif } } diff --git a/src/Foundation/MonoTouchException.cs b/src/Foundation/MonoTouchException.cs deleted file mode 100644 index 2d07d1ee6af7..000000000000 --- a/src/Foundation/MonoTouchException.cs +++ /dev/null @@ -1,72 +0,0 @@ -#if !MONOMAC && !NET - -using System; -using System.Text; - -#nullable enable - -namespace Foundation { - public class MonoTouchException : Exception { - NSException? native_exc; - - public MonoTouchException () : base () - { - native_exc = new NSException ("default", String.Empty, null); - } - - public MonoTouchException (NSException exc) : base () - { - native_exc = exc; - } - - public NSException? NSException { - get { - return native_exc; - } - } - - public string? Reason { - get { - return native_exc?.Reason; - } - } - - public string? Name { - get { - return native_exc?.Name; - } - } - - public override string Message { - get { - var sb = new StringBuilder ("Objective-C exception thrown. Name: ").Append (Name); - sb.Append (" Reason: ").AppendLine (Reason); - sb.AppendLine ("Native stack trace:"); - AppendNativeStackTrace (sb); - return sb.ToString (); - } - } - - void AppendNativeStackTrace (StringBuilder sb) - { - var callStackSymbols = native_exc?.CallStackSymbols; - if (callStackSymbols is not null) { - foreach (var symbol in callStackSymbols) - sb.Append ('\t').AppendLine (symbol); - } - } - - public override string ToString () - { - var msg = base.ToString (); - if (native_exc is null) - return msg; - - var sb = new StringBuilder (msg); - AppendNativeStackTrace (sb); - return sb.ToString (); - } - } -} - -#endif // !MONOMAC && !NET diff --git a/src/Foundation/NSArray.cs b/src/Foundation/NSArray.cs index 47e644bbb58f..7bef240dcded 100644 --- a/src/Foundation/NSArray.cs +++ b/src/Foundation/NSArray.cs @@ -32,10 +32,6 @@ using CoreFoundation; using ObjCRuntime; -#if !NET -using NativeHandle = System.IntPtr; -#endif - // Disable until we get around to enable + fix any issues. #nullable disable @@ -232,7 +228,6 @@ static public NSArray FromStrings (IReadOnlyList items) } } -#if NET /// Create an from the specified pointers. /// Array of pointers (to instances). /// If the array is null, an is thrown. @@ -246,7 +241,6 @@ static internal NSArray FromIntPtrs (IntPtr [] items) return Runtime.GetNSObject (NSArray.FromObjects ((IntPtr) valuesPtr, items.Length))!; } } -#endif static public NSArray FromIntPtrs (NativeHandle [] vals) { @@ -274,15 +268,7 @@ internal static nuint GetCount (IntPtr handle) internal static NativeHandle GetAtIndex (NativeHandle handle, nuint i) { -#if NET return Messaging.NativeHandle_objc_msgSend_UIntPtr (handle, Selector.GetHandle ("objectAtIndex:"), (UIntPtr) i); -#else -#if MONOMAC - return Messaging.IntPtr_objc_msgSend_UIntPtr (handle, selObjectAtIndex_XHandle, (UIntPtr) i); -#else - return Messaging.IntPtr_objc_msgSend_UIntPtr (handle, Selector.GetHandle ("objectAtIndex:"), (UIntPtr) i); -#endif -#endif } [Obsolete ("Use of 'CFArray.StringArrayFromHandle' offers better performance.")] diff --git a/src/Foundation/NSArray_1.cs b/src/Foundation/NSArray_1.cs index 4754337a7e7e..6d093768552b 100644 --- a/src/Foundation/NSArray_1.cs +++ b/src/Foundation/NSArray_1.cs @@ -17,10 +17,6 @@ using ObjCRuntime; -#if !NET -using NativeHandle = System.IntPtr; -#endif - namespace Foundation { #if false // https://github.com/xamarin/xamarin-macios/issues/15577 public delegate bool NSOrderedCollectionDifferenceEquivalenceTest (TValue? first, TValue? second); @@ -105,27 +101,15 @@ public TKey this [nint idx] { #if false // https://github.com/xamarin/xamarin-macios/issues/15577 -#if !NET - [TV (13,0), iOS (13,0)] -#else [SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos")] -#endif public NSOrderedCollectionDifference? GetDifference (TKey[] other, NSOrderedCollectionDifferenceCalculationOptions options) => Runtime.GetNSObject > (_GetDifference (NSArray.FromNSObjects (other), options)); -#if !NET - [TV (13,0), iOS (13,0)] -#else [SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos")] -#endif public NSOrderedCollectionDifference? GetDifference (TKey[] other) => Runtime.GetNSObject > (_GetDifference (NSArray.FromNSObjects (other))); -#if !NET - [TV (13,0), iOS (13,0)] -#else [SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos")] -#endif public TKey[]? GetArrayByApplyingDifference (NSOrderedCollectionDifference difference) => NSArray.ArrayFromHandle (_GetArrayByApplyingDifference (difference)); static readonly NSOrderedCollectionDifferenceEquivalenceTestProxy static_DiffEqualityGeneric = DiffEqualityHandlerGeneric; @@ -142,11 +126,7 @@ static bool DiffEqualityHandlerGeneric (IntPtr block, IntPtr first, IntPtr secon return false; } -#if !NET - [TV (13,0), iOS (13,0)] -#else [SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos")] -#endif public NSOrderedCollectionDifference? GetDifferenceFromArray (NSArray other, NSOrderedCollectionDifferenceCalculationOptions options, NSOrderedCollectionDifferenceEquivalenceTest equivalenceTest) { if (equivalenceTest is null) diff --git a/src/Foundation/NSAttributedString.cs b/src/Foundation/NSAttributedString.cs index 5c8de4d962f3..90c6c4197a46 100644 --- a/src/Foundation/NSAttributedString.cs +++ b/src/Foundation/NSAttributedString.cs @@ -237,7 +237,6 @@ public string? Value { return Runtime.GetNSObject (LowLevelGetAttributes (location, out effectiveRange)); } -#if NET public IntPtr LowLevelGetAttributes (nint location, out NSRange effectiveRange) { unsafe { @@ -246,7 +245,6 @@ public IntPtr LowLevelGetAttributes (nint location, out NSRange effectiveRange) } } } -#endif public NSAttributedString (string str, CTStringAttributes? attributes) : this (str, attributes?.Dictionary) diff --git a/src/Foundation/NSObject2.cs b/src/Foundation/NSObject2.cs index 83e42eb6d954..e9963248291f 100644 --- a/src/Foundation/NSObject2.cs +++ b/src/Foundation/NSObject2.cs @@ -33,9 +33,7 @@ using System.Runtime.Versioning; using System.Diagnostics; -#if NET using System.Runtime.InteropServices.ObjectiveC; -#endif using ObjCRuntime; #if !COREBUILD @@ -47,16 +45,11 @@ using CoreGraphics; #endif -#if !NET -using NativeHandle = System.IntPtr; -#endif - // Disable until we get around to enable + fix any issues. #nullable disable namespace Foundation { -#if NET [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("maccatalyst")] [SupportedOSPlatform ("macos")] @@ -64,15 +57,7 @@ namespace Foundation { public enum NSObjectFlag { Empty, } -#else - public class NSObjectFlag { - public static readonly NSObjectFlag Empty; - - NSObjectFlag () { } - } -#endif -#if NET // This interface will be made public when the managed static registrar is used. internal interface INSObjectFactory { // The method will be implemented via custom linker step if the managed static registrar is used @@ -80,9 +65,8 @@ internal interface INSObjectFactory { [MethodImpl(MethodImplOptions.NoInlining)] virtual static NSObject _Xamarin_ConstructNSObject (NativeHandle handle) => null; } -#endif -#if NET && !COREBUILD +#if !COREBUILD [ObjectiveCTrackedType] [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("maccatalyst")] @@ -95,9 +79,7 @@ public partial class NSObject : INativeObject , IEquatable , IDisposable #endif -#if NET , INSObjectFactory -#endif { #if !COREBUILD const string selConformsToProtocol = "conformsToProtocol:"; @@ -114,9 +96,6 @@ public partial class NSObject : INativeObject NativeHandle handle; IntPtr super; /* objc_super* */ -#if !NET - Flags flags; -#else // See "Toggle-ref support for CoreCLR" in coreclr-bridge.m for more information. Flags actual_flags; internal unsafe Runtime.TrackedObjectInfo* tracked_object_info; @@ -137,7 +116,6 @@ unsafe Flags flags { tracked_object_info->Flags = value; } } -#endif // NET // This enum has a native counterpart in runtime.h [Flags] @@ -220,21 +198,13 @@ public NSObject (NSObjectFlag x) } [EditorBrowsable (EditorBrowsableState.Never)] -#if NET protected internal NSObject (NativeHandle handle) -#else - public NSObject (NativeHandle handle) -#endif : this (handle, false) { } [EditorBrowsable (EditorBrowsableState.Never)] -#if NET protected NSObject (NativeHandle handle, bool alloced) -#else - public NSObject (NativeHandle handle, bool alloced) -#endif { this.handle = handle; InitializeObject (alloced); @@ -251,21 +221,17 @@ public void Dispose () GC.SuppressFinalize (this); } -#if NET // This method should never be called when using the managed static registrar, so assert that never happens by throwing an exception in that case. // This method doesn't necessarily work with NativeAOT, but this is covered by the exception, because the managed static registrar is required for NativeAOT. // // IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(Type)'. The return value of method 'ObjCRuntime.Runtime.GetGCHandleTarget(IntPtr)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [UnconditionalSuppressMessage("", "IL2072", Justification = "The APIs this method tries to access are marked by other means, so this is linker-safe.")] -#endif internal static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, Flags flags) { -#if NET // Note that the code in this method doesn't necessarily work with NativeAOT, so assert that never happens by throwing an exception if using the managed static registrar (which is required for NativeAOT) if (Runtime.IsManagedStaticRegistrar) { throw new System.Diagnostics.UnreachableException (); } -#endif // This function is called from native code before any constructors have executed. var type = (Type) Runtime.GetGCHandleTarget (type_gchandle); @@ -312,33 +278,29 @@ internal static NativeHandle Initialize () return class_ptr; } -#if NET internal Flags FlagsInternal { get { return flags; } set { flags = value; } } -#endif -#if !NET || !__MACOS__ +#if !__MACOS__ [MethodImplAttribute (MethodImplOptions.InternalCall)] extern static void RegisterToggleRef (NSObject obj, IntPtr handle, bool isCustomType); -#endif // !NET || !__MACOS__ +#endif // !__MACOS__ [DllImport ("__Internal")] static extern void xamarin_release_managed_ref (IntPtr handle, byte user_type); static void RegisterToggleReference (NSObject obj, IntPtr handle, bool isCustomType) { -#if NET && __MACOS__ +#if __MACOS__ Runtime.RegisterToggleReferenceCoreCLR (obj, handle, isCustomType); -#elif NET +#else if (Runtime.IsCoreCLR) { Runtime.RegisterToggleReferenceCoreCLR (obj, handle, isCustomType); } else { RegisterToggleRef (obj, handle, isCustomType); } -#else - RegisterToggleRef (obj, handle, isCustomType); #endif } @@ -510,41 +472,24 @@ public virtual bool ConformsToProtocol (NativeHandle protocol) // the linker/trimmer will remove the following code if the dynamic registrar is removed from the app var classHandle = ClassHandle; lock (Runtime.protocol_cache) { -#if NET ref var map = ref CollectionsMarshal.GetValueRefOrAddDefault (Runtime.protocol_cache, classHandle, out var exists); if (!exists) map = new (); ref var result = ref CollectionsMarshal.GetValueRefOrAddDefault (map, protocol, out exists); if (!exists) result = DynamicConformsToProtocol (protocol); -#else - bool new_map = false; - if (!Runtime.protocol_cache.TryGetValue (classHandle, out var map)) { - map = new (); - new_map = true; - Runtime.protocol_cache.Add (classHandle, map); - } - if (new_map || !map.TryGetValue (protocol, out var result)) { - result = DynamicConformsToProtocol (protocol); - map.Add (protocol, result); - } -#endif return result; } } -#if NET // Note that this method does not work with NativeAOT, so throw an exception in that case. // IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [UnconditionalSuppressMessage ("", "IL2075", Justification = "The APIs this method tries to access are marked by other means, so this is linker-safe.")] -#endif bool DynamicConformsToProtocol (NativeHandle protocol) { -#if NET // Note that this method does not work with NativeAOT, so throw an exception in that case. if (Runtime.IsNativeAOT) throw Runtime.CreateNativeAOTNotSupportedException (); -#endif object [] adoptedProtocols = GetType ().GetCustomAttributes (typeof (AdoptsAttribute), true); foreach (AdoptsAttribute adopts in adoptedProtocols) { @@ -656,12 +601,10 @@ public NativeHandle Handle { handle = value; -#if NET unsafe { if (tracked_object_info is not null) tracked_object_info->Handle = value; } -#endif if (handle != IntPtr.Zero) Runtime.RegisterNSObject (this, handle); @@ -712,15 +655,7 @@ private bool AllocIfNeeded () private void InvokeOnMainThread (Selector sel, NSObject obj, bool wait) { -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (this.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), sel.Handle, obj.GetHandle (), wait ? (byte) 1 : (byte) 0); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (this.Handle, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, sel.Handle, obj.GetHandle (), wait ? (byte) 1 : (byte) 0); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (this.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), sel.Handle, obj.GetHandle (), wait ? (byte) 1 : (byte) 0); -#endif -#endif } public void BeginInvokeOnMainThread (Selector sel, NSObject obj) @@ -736,70 +671,30 @@ public void InvokeOnMainThread (Selector sel, NSObject obj) public void BeginInvokeOnMainThread (Action action) { var d = new NSAsyncActionDispatcher (action); -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), NSDispatcher.Selector.Handle, d.Handle, 0); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, - NSDispatcher.Selector.Handle, d.Handle, 0); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 0); -#endif -#endif } internal void BeginInvokeOnMainThread (System.Threading.SendOrPostCallback cb, object state) { var d = new NSAsyncSynchronizationContextDispatcher (cb, state); -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 0); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, - NSDispatcher.Selector.Handle, d.Handle, 0); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 0); -#endif -#endif } public void InvokeOnMainThread (Action action) { using (var d = new NSActionDispatcher (action)) { -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, - NSDispatcher.Selector.Handle, d.Handle, 1); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); -#endif -#endif } } internal void InvokeOnMainThread (System.Threading.SendOrPostCallback cb, object state) { using (var d = new NSSynchronizationContextDispatcher (cb, state)) { -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, - NSDispatcher.Selector.Handle, d.Handle, 1); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); -#endif -#endif } } @@ -883,27 +778,11 @@ public void SetValueForKeyPath (NativeHandle handle, NSString keyPath) { if (keyPath is null) throw new ArgumentNullException ("keyPath"); -#if NET if (IsDirectBinding) { ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle_NativeHandle (this.Handle, Selector.GetHandle ("setValue:forKeyPath:"), handle, keyPath.Handle); } else { ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle_NativeHandle (this.SuperHandle, Selector.GetHandle ("setValue:forKeyPath:"), handle, keyPath.Handle); } -#else -#if MONOMAC - if (IsDirectBinding) { - ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr (this.Handle, selSetValue_ForKeyPath_XHandle, handle, keyPath.Handle); - } else { - ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr_IntPtr (this.SuperHandle, selSetValue_ForKeyPath_XHandle, handle, keyPath.Handle); - } -#else - if (IsDirectBinding) { - ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr (this.Handle, Selector.GetHandle ("setValue:forKeyPath:"), handle, keyPath.Handle); - } else { - ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr_IntPtr (this.SuperHandle, Selector.GetHandle ("setValue:forKeyPath:"), handle, keyPath.Handle); - } -#endif -#endif } // if IsDirectBinding is false then we _likely_ have managed state and it's up to the subclass to provide @@ -1017,15 +896,7 @@ static internal void Add (NSObject handle) static void ScheduleDrain () { -#if NET Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (class_ptr, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), Selector.GetHandle ("drain:"), NativeHandle.Zero, 0); -#else -#if MONOMAC - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (class_ptr, Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle, drainHandle, IntPtr.Zero, 0); -#else - Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (class_ptr, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), Selector.GetHandle ("drain:"), IntPtr.Zero, 0); -#endif -#endif } static bool draining; @@ -1150,12 +1021,10 @@ public static void InvokeInBackground (Action action) } #if !COREBUILD -#if NET [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("maccatalyst")] [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("tvos")] -#endif public class NSObservedChange { NSDictionary dict; public NSObservedChange (NSDictionary source) diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index 571e69c12de9..e8528a928746 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -58,9 +58,6 @@ namespace System.Net.Http { namespace Foundation { #endif -#if !NET - public delegate bool NSUrlSessionHandlerTrustOverrideCallback (NSUrlSessionHandler sender, SecTrust trust); -#endif public delegate bool NSUrlSessionHandlerTrustOverrideForUrlCallback (NSUrlSessionHandler sender, string url, SecTrust trust); // useful extensions for the class in order to set it in a header @@ -305,21 +302,6 @@ public ICredentials? Credentials { } } -#if !NET - NSUrlSessionHandlerTrustOverrideCallback? trustOverride; - - [Obsolete ("Use the 'TrustOverrideForUrl' property instead.")] - public NSUrlSessionHandlerTrustOverrideCallback? TrustOverride { - get { - return trustOverride; - } - set { - EnsureModifiability (); - trustOverride = value; - } - } -#endif - NSUrlSessionHandlerTrustOverrideForUrlCallback? trustOverrideForUrl; public NSUrlSessionHandlerTrustOverrideForUrlCallback? TrustOverrideForUrl { @@ -502,9 +484,6 @@ async Task CreateRequest (HttpRequestMessage request) return nsrequest; } -#if (SYSTEM_NET_HTTP || MONOMAC) && !NET - internal -#endif protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) { Volatile.Write (ref sentRequest, true); @@ -545,7 +524,6 @@ protected override async Task SendAsync (HttpRequestMessage return await inflightData.CompletionSource.Task.ConfigureAwait (false); } -#if NET // Properties that will be called by the default HttpClientHandler // NSUrlSession handler automatically handles decompression, and there doesn't seem to be a way to turn it off. @@ -805,7 +783,6 @@ public bool UseProxy { ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (value), value, "It's not possible to disable the use of system proxies.");; } } -#endif // NET partial class NSUrlSessionHandlerDelegate : NSUrlSessionDataDelegate { readonly NSUrlSessionHandler sessionHandler; @@ -1053,17 +1030,6 @@ void DidReceiveChallengeImpl (NSUrlSession session, NSUrlSessionTask task, NSUrl var trustCallbackForUrl = sessionHandler.TrustOverrideForUrl; var trustSec = false; var usedCallback = false; -#if !NET - var trustCallback = sessionHandler.TrustOverride; - var hasCallBack = trustCallback is not null || trustCallbackForUrl is not null; - if (hasCallBack && challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodServerTrust) { - // if one of the delegates allows to ignore the cert, do it. We check first the one that takes the url because is more precisse, later the - // more general one. Since we are using nullables, if the delegate is not present, by default is false - trustSec = (trustCallbackForUrl?.Invoke (sessionHandler, inflight.RequestUrl, challenge.ProtectionSpace.ServerSecTrust) ?? false) || - (trustCallback?.Invoke (sessionHandler, challenge.ProtectionSpace.ServerSecTrust) ?? false); - usedCallback = true; - } -#else if (challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodServerTrust) { // if the trust delegate allows to ignore the cert, do it. Since we are using nullables, if the delegate is not present, by default is false if (trustCallbackForUrl is not null) { @@ -1073,7 +1039,6 @@ void DidReceiveChallengeImpl (NSUrlSession session, NSUrlSessionTask task, NSUrl usedCallback = true; } } -#endif if (usedCallback) { if (trustSec) { @@ -1089,7 +1054,7 @@ void DidReceiveChallengeImpl (NSUrlSession session, NSUrlSessionTask task, NSUrl } return; } -#if NET + if (sessionHandler.ClientCertificateOptions == ClientCertificateOption.Manual && challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodClientCertificate) { var certificate = CertificateHelper.GetEligibleClientCertificate (sessionHandler.ClientCertificates); if (certificate is not null) { @@ -1100,7 +1065,6 @@ void DidReceiveChallengeImpl (NSUrlSession session, NSUrlSessionTask task, NSUrl return; } } -#endif // case for the basic auth failing up front. As per apple documentation: // The URL Loading System is designed to handle various aspects of the HTTP protocol for you. As a result, you should not modify the following headers using @@ -1307,9 +1271,6 @@ protected override Task SerializeToStreamAsync (Stream stream, TransportContext? return content.CopyToAsync (stream, bufferSize, cancellationToken); } -#if !NET - internal -#endif protected override bool TryComputeLength (out long length) { if (!content.CanSeek) { @@ -1565,16 +1526,9 @@ protected override bool SetCFClientFlags (CFStreamEventType inFlags, IntPtr inCa } [Preserve (Conditional = true)] -#if NET public override void Schedule (NSRunLoop aRunLoop, NSString nsMode) -#else - public override void Schedule (NSRunLoop aRunLoop, string mode) -#endif { var cfRunLoop = aRunLoop.GetCFRunLoop (); -#if !NET - var nsMode = new NSString (mode); -#endif cfRunLoop.AddSource (source, nsMode); @@ -1587,17 +1541,9 @@ public override void Schedule (NSRunLoop aRunLoop, string mode) } [Preserve (Conditional = true)] -#if NET public override void Unschedule (NSRunLoop aRunLoop, NSString nsMode) -#else - public override void Unschedule (NSRunLoop aRunLoop, string mode) -#endif { var cfRunLoop = aRunLoop.GetCFRunLoop (); -#if !NET - var nsMode = new NSString (mode); -#endif - cfRunLoop.RemoveSource (source, nsMode); } @@ -1607,7 +1553,6 @@ protected override void Dispose (bool disposing) } } -#if NET static class CertificateHelper { // Based on https://github.com/dotnet/runtime/blob/c2848c582f5d6ae42c89f5bfe0818687ab3345f0/src/libraries/Common/src/System/Net/Security/CertificateHelper.cs // with the NetEventSource code removed and namespace changed. @@ -1673,6 +1618,5 @@ static bool IsValidForDigitalSignatureUsage (X509KeyUsageExtension ku) return (ku.KeyUsages & RequiredUsages) == RequiredUsages; } } -#endif } } diff --git a/src/frameworks.sources b/src/frameworks.sources index fbe6e6aae8dd..31ad99a1a26a 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -835,7 +835,6 @@ FOUNDATION_CORE_SOURCES = \ FOUNDATION_SOURCES = \ Foundation/Additions.cs \ Foundation/Compat.cs \ - Foundation/MonoTouchException.cs \ Foundation/NSAppleEventDescriptor.cs \ Foundation/NSArray.cs \ Foundation/NSArray_1.cs \ From 739ce5d34c14d9069fe444790eb09a23e2491819 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Fri, 17 Jan 2025 11:02:41 +0000 Subject: [PATCH 2/2] Auto-format source code --- src/Foundation/NSArray.cs | 2 +- src/Foundation/NSAttributedString.cs | 2 +- src/Foundation/NSObject2.cs | 17 ++++++++--------- src/Foundation/NSUrlSessionHandler.cs | 17 ++++++++--------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Foundation/NSArray.cs b/src/Foundation/NSArray.cs index 7bef240dcded..fe122cd31608 100644 --- a/src/Foundation/NSArray.cs +++ b/src/Foundation/NSArray.cs @@ -237,7 +237,7 @@ static internal NSArray FromIntPtrs (IntPtr [] items) throw new ArgumentNullException (nameof (items)); unsafe { - fixed (IntPtr *valuesPtr = items) + fixed (IntPtr* valuesPtr = items) return Runtime.GetNSObject (NSArray.FromObjects ((IntPtr) valuesPtr, items.Length))!; } } diff --git a/src/Foundation/NSAttributedString.cs b/src/Foundation/NSAttributedString.cs index 90c6c4197a46..f6a40823c386 100644 --- a/src/Foundation/NSAttributedString.cs +++ b/src/Foundation/NSAttributedString.cs @@ -240,7 +240,7 @@ public string? Value { public IntPtr LowLevelGetAttributes (nint location, out NSRange effectiveRange) { unsafe { - fixed (NSRange *effectiveRangePtr = &effectiveRange) { + fixed (NSRange* effectiveRangePtr = &effectiveRange) { return LowLevelGetAttributes (location, (IntPtr) effectiveRangePtr); } } diff --git a/src/Foundation/NSObject2.cs b/src/Foundation/NSObject2.cs index e9963248291f..848b69e377c0 100644 --- a/src/Foundation/NSObject2.cs +++ b/src/Foundation/NSObject2.cs @@ -62,7 +62,7 @@ public enum NSObjectFlag { internal interface INSObjectFactory { // The method will be implemented via custom linker step if the managed static registrar is used // for NSObject subclasses which have an (NativeHandle) or (IntPtr) constructor. - [MethodImpl(MethodImplOptions.NoInlining)] + [MethodImpl (MethodImplOptions.NoInlining)] virtual static NSObject _Xamarin_ConstructNSObject (NativeHandle handle) => null; } @@ -79,8 +79,7 @@ public partial class NSObject : INativeObject , IEquatable , IDisposable #endif - , INSObjectFactory - { + , INSObjectFactory { #if !COREBUILD const string selConformsToProtocol = "conformsToProtocol:"; const string selEncodeWithCoder = "encodeWithCoder:"; @@ -225,7 +224,7 @@ public void Dispose () // This method doesn't necessarily work with NativeAOT, but this is covered by the exception, because the managed static registrar is required for NativeAOT. // // IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(Type)'. The return value of method 'ObjCRuntime.Runtime.GetGCHandleTarget(IntPtr)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. - [UnconditionalSuppressMessage("", "IL2072", Justification = "The APIs this method tries to access are marked by other means, so this is linker-safe.")] + [UnconditionalSuppressMessage ("", "IL2072", Justification = "The APIs this method tries to access are marked by other means, so this is linker-safe.")] internal static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, Flags flags) { // Note that the code in this method doesn't necessarily work with NativeAOT, so assert that never happens by throwing an exception if using the managed static registrar (which is required for NativeAOT) @@ -672,21 +671,21 @@ public void BeginInvokeOnMainThread (Action action) { var d = new NSAsyncActionDispatcher (action); Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - NSDispatcher.Selector.Handle, d.Handle, 0); + NSDispatcher.Selector.Handle, d.Handle, 0); } internal void BeginInvokeOnMainThread (System.Threading.SendOrPostCallback cb, object state) { var d = new NSAsyncSynchronizationContextDispatcher (cb, state); Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 0); + Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 0); } public void InvokeOnMainThread (Action action) { using (var d = new NSActionDispatcher (action)) { - Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); + Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), + Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); } } @@ -694,7 +693,7 @@ internal void InvokeOnMainThread (System.Threading.SendOrPostCallback cb, object { using (var d = new NSSynchronizationContextDispatcher (cb, state)) { Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), - Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); + Selector.GetHandle (NSDispatcher.SelectorName), d.Handle, 1); } } diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index e8528a928746..817116cb8863 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -581,7 +581,7 @@ public int MaxAutomaticRedirections { set { // I believe it's possible to implement support for MaxAutomaticRedirections (it just has to be done) if (value != int.MaxValue) - ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (value), value, "It's not possible to lower the max number of automatic redirections.");; + ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (value), value, "It's not possible to lower the max number of automatic redirections."); ; } } @@ -635,7 +635,7 @@ public IWebProxy? Proxy { set { if (value is not null) throw new PlatformNotSupportedException (); - } + } } // There doesn't seem to be a trivial way to specify the protocols to accept (or not) @@ -674,8 +674,7 @@ internal bool TryInvokeServerCertificateCustomValidationCallback (HttpRequestMes return true; } - sealed class ServerCertificateCustomValidationCallbackHelper - { + sealed class ServerCertificateCustomValidationCallbackHelper { public Func Callback { get; private set; } public ServerCertificateCustomValidationCallbackHelper (Func callback) @@ -685,7 +684,7 @@ public ServerCertificateCustomValidationCallbackHelper (Func 0 ? certificates [0] : null; using X509Chain chain = CreateChain (certificates); SslPolicyErrors sslPolicyErrors = EvaluateSslPolicyErrors (certificate, chain, secTrust); @@ -693,7 +692,7 @@ public bool Invoke (HttpRequestMessage request, SecTrust secTrust) return Callback (request, certificate, chain, sslPolicyErrors); } - X509Certificate2[] ConvertCertificates (SecTrust secTrust) + X509Certificate2 [] ConvertCertificates (SecTrust secTrust) { var certificates = new X509Certificate2 [secTrust.Count]; @@ -726,7 +725,7 @@ static bool IsSecTrustGetCertificateChainSupported { } } - X509Chain CreateChain (X509Certificate2[] certificates) + X509Chain CreateChain (X509Certificate2 [] certificates) { // inspired by https://github.com/dotnet/runtime/blob/99d21b9276ebe8f7bea7fb3ba74dca9fca625fe2/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs#L691-L696 var chain = new X509Chain (); @@ -739,7 +738,7 @@ X509Chain CreateChain (X509Certificate2[] certificates) SslPolicyErrors EvaluateSslPolicyErrors (X509Certificate2? certificate, X509Chain chain, SecTrust secTrust) { var sslPolicyErrors = SslPolicyErrors.None; - + try { if (certificate is null) { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable; @@ -780,7 +779,7 @@ public bool UseProxy { get => true; set { if (!value) - ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (value), value, "It's not possible to disable the use of system proxies.");; + ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (value), value, "It's not possible to disable the use of system proxies."); ; } }