-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RGen] Implement the generation of the Notifications helper class. (#…
…22265) Implement the notifications helper class for those properties marked as notifications. Code supports the same configuration options as bgen and the test ensures that all configurations are tested: 1. No special config 2. Special args. 3. Special notification center. 4. Special args and notification center. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
- Loading branch information
1 parent
74636f5
commit 49763bb
Showing
5 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedNSUserDefaults.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// <auto-generated /> | ||
|
||
#nullable enable | ||
|
||
using Foundation; | ||
using ObjCBindings; | ||
using ObjCRuntime; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Drawing; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
using System.Threading.Tasks; | ||
|
||
namespace Foundation; | ||
|
||
[Register ("NSUserDefaults", true)] | ||
public partial class NSUserDefaults | ||
{ | ||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
static readonly NativeHandle class_ptr = Class.GetHandle ("NSUserDefaults"); | ||
|
||
public override NativeHandle ClassHandle => class_ptr; | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[DesignatedInitializer] | ||
[Export ("init")] | ||
public NSUserDefaults () : base (NSObjectFlag.Empty) | ||
{ | ||
if (IsDirectBinding) | ||
InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("init")), "init"); | ||
else | ||
InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, global::ObjCRuntime.Selector.GetHandle ("init")), "init"); | ||
} | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[EditorBrowsable (EditorBrowsableState.Advanced)] | ||
protected NSUserDefaults (NSObjectFlag t) : base (t) {} | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[EditorBrowsable (EditorBrowsableState.Advanced)] | ||
protected internal NSUserDefaults (NativeHandle handle) : base (handle) {} | ||
|
||
static Foundation.NSString? _CompletedInitialSyncNotification; | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[Advice ("Use 'NSUserDefaults.Notifications.CompletedInitialSyncNotification' helper method instead.")] | ||
public static partial Foundation.NSString CompletedInitialSyncNotification | ||
{ | ||
get | ||
{ | ||
if (_CompletedInitialSyncNotification is null) | ||
_CompletedInitialSyncNotification = Dlfcn.GetStringConstant (Libraries.Foundation.Handle, "NSUbiquitousUserDefaultsCompletedInitialSyncNotification")!; | ||
return _CompletedInitialSyncNotification; | ||
} | ||
} | ||
|
||
static Foundation.NSString? _DidChangeAccountsNotification; | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[Advice ("Use 'NSUserDefaults.Notifications.DidChangeAccountsNotification' helper method instead.")] | ||
public static partial Foundation.NSString DidChangeAccountsNotification | ||
{ | ||
get | ||
{ | ||
if (_DidChangeAccountsNotification is null) | ||
_DidChangeAccountsNotification = Dlfcn.GetStringConstant (Libraries.Foundation.Handle, "NSUbiquitousUserDefaultsDidChangeAccountsNotification")!; | ||
return _DidChangeAccountsNotification; | ||
} | ||
} | ||
|
||
static Foundation.NSString? _NoCloudAccountNotification; | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[Advice ("Use 'NSUserDefaults.Notifications.NoCloudAccountNotification' helper method instead.")] | ||
public static partial Foundation.NSString NoCloudAccountNotification | ||
{ | ||
get | ||
{ | ||
if (_NoCloudAccountNotification is null) | ||
_NoCloudAccountNotification = Dlfcn.GetStringConstant (Libraries.Foundation.Handle, "NSUbiquitousUserDefaultsNoCloudAccountNotification")!; | ||
return _NoCloudAccountNotification; | ||
} | ||
} | ||
|
||
static Foundation.NSString? _SizeLimitExceededNotification; | ||
|
||
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||
[Advice ("Use 'NSUserDefaults.Notifications.SizeLimitExceededNotification' helper method instead.")] | ||
public static partial Foundation.NSString SizeLimitExceededNotification | ||
{ | ||
get | ||
{ | ||
if (_SizeLimitExceededNotification is null) | ||
_SizeLimitExceededNotification = Dlfcn.GetStringConstant (Libraries.Foundation.Handle, "NSUserDefaultsSizeLimitExceededNotification")!; | ||
return _SizeLimitExceededNotification; | ||
} | ||
} | ||
|
||
public static partial class Notifications | ||
{ | ||
|
||
public static NSObject ObserveCompletedInitialSync (EventHandler<Foundation.MyNotificationArgs> handler) | ||
{ | ||
return SharedWorkspace.NotificationCenter.AddObserver (CompletedInitialSyncNotification, notification => handler (null, new Foundation.MyNotificationArgs (notification))); | ||
} | ||
|
||
public static NSObject ObserveCompletedInitialSync (NSObject objectToObserve, EventHandler<Foundation.MyNotificationArgs> handler) | ||
{ | ||
return SharedWorkspace.NotificationCenter.AddObserver (CompletedInitialSyncNotification, notification => handler (null, new Foundation.MyNotificationArgs (notification)), objectToObserve); | ||
} | ||
|
||
public static NSObject ObserveDidChangeAccounts (EventHandler<Foundation.MyNotificationArgs> handler) | ||
{ | ||
return NSNotificationCenter.DefaultCenter.AddObserver (DidChangeAccountsNotification, notification => handler (null, new Foundation.MyNotificationArgs (notification))); | ||
} | ||
|
||
public static NSObject ObserveDidChangeAccounts (NSObject objectToObserve, EventHandler<Foundation.MyNotificationArgs> handler) | ||
{ | ||
return NSNotificationCenter.DefaultCenter.AddObserver (DidChangeAccountsNotification, notification => handler (null, new Foundation.MyNotificationArgs (notification)), objectToObserve); | ||
} | ||
|
||
public static NSObject ObserveNoCloudAccount (EventHandler<Foundation.NSNotificationEventArgs> handler) | ||
{ | ||
return SharedWorkspace.NotificationCenter.AddObserver (NoCloudAccountNotification, notification => handler (null, new Foundation.NSNotificationEventArgs (notification))); | ||
} | ||
|
||
public static NSObject ObserveNoCloudAccount (NSObject objectToObserve, EventHandler<Foundation.NSNotificationEventArgs> handler) | ||
{ | ||
return SharedWorkspace.NotificationCenter.AddObserver (NoCloudAccountNotification, notification => handler (null, new Foundation.NSNotificationEventArgs (notification)), objectToObserve); | ||
} | ||
|
||
public static NSObject ObserveSizeLimitExceeded (EventHandler<Foundation.NSNotificationEventArgs> handler) | ||
{ | ||
return NSNotificationCenter.DefaultCenter.AddObserver (SizeLimitExceededNotification, notification => handler (null, new Foundation.NSNotificationEventArgs (notification))); | ||
} | ||
|
||
public static NSObject ObserveSizeLimitExceeded (NSObject objectToObserve, EventHandler<Foundation.NSNotificationEventArgs> handler) | ||
{ | ||
return NSNotificationCenter.DefaultCenter.AddObserver (SizeLimitExceededNotification, notification => handler (null, new Foundation.NSNotificationEventArgs (notification)), objectToObserve); | ||
} | ||
|
||
} | ||
// TODO: add binding code here | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/NSUserDefaults.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.Versioning; | ||
using Foundation; | ||
using ObjCBindings; | ||
|
||
namespace Foundation | ||
|
||
public partial class MyNotificationArgs { | ||
|
||
} | ||
|
||
[BindingType<Class>] | ||
public partial class NSUserDefaults : NSObject { | ||
|
||
// default values | ||
|
||
[Field<Property> ("NSUserDefaultsSizeLimitExceededNotification", Flags = Property.Notification)] | ||
public static partial NSString SizeLimitExceededNotification { get; } | ||
|
||
// special notification center | ||
[Field<Property> ("NSUbiquitousUserDefaultsNoCloudAccountNotification", Flags = Property.Notification, NotificationCenter = "SharedWorkspace.NotificationCenter")] | ||
public static partial NSString NoCloudAccountNotification { get; } | ||
|
||
// special args | ||
[Field<Property> ("NSUbiquitousUserDefaultsDidChangeAccountsNotification", Flags = Property.Notification, Type = typeof (MyNotificationArgs))] | ||
public static partial NSString DidChangeAccountsNotification { get; } | ||
|
||
// full customization | ||
[Field<Property> ("NSUbiquitousUserDefaultsCompletedInitialSyncNotification", Flags = Property.Notification, Type = typeof (MyNotificationArgs), NotificationCenter = "SharedWorkspace.NotificationCenter")] | ||
public static partial NSString CompletedInitialSyncNotification { get; } | ||
} |
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.