-
Notifications
You must be signed in to change notification settings - Fork 554
[RGen] Generate the initWithCoder: constructor. #23803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mandel-macaque
wants to merge
2
commits into
dev/mandel/is-nscoder
from
dev/mandel/add-initWithCoder-class
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
134 changes: 134 additions & 0 deletions
134
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedNSCodingSubclass.cs
This file contains hidden or 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,134 @@ | ||||||
| // <auto-generated /> | ||||||
|
|
||||||
| #nullable enable | ||||||
|
|
||||||
| using AVFoundation; | ||||||
| using CoreGraphics; | ||||||
| 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; | ||||||
|
|
||||||
| namespace UIKit; | ||||||
|
|
||||||
| [SupportedOSPlatform ("macos")] | ||||||
| [SupportedOSPlatform ("ios")] | ||||||
| [SupportedOSPlatform ("tvos")] | ||||||
| [SupportedOSPlatform ("maccatalyst13.1")] | ||||||
| [Register ("NSCodingSubclass", true)] | ||||||
| public partial class NSCodingSubclass | ||||||
| { | ||||||
| [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||||||
| static readonly global::ObjCRuntime.NativeHandle class_ptr = global::ObjCRuntime.Class.GetHandle ("NSCodingSubclass"); | ||||||
|
|
||||||
| /// <summary>The Objective-C class handle for this class.</summary> | ||||||
| /// <value>The pointer to the Objective-C class.</value> | ||||||
| /// <remarks> | ||||||
| /// Each managed class mirrors an unmanaged Objective-C class. | ||||||
| /// This value contains the pointer to the Objective-C class. | ||||||
| /// It is similar to calling the managed <see cref=\"ObjCRuntime.Class.GetHandle(string)\" /> or the native <see href=\"https://developer.apple.com/documentation/objectivec/1418952-objc_getclass\">objc_getClass</see> method with the type name. | ||||||
| /// </remarks> | ||||||
| public override global::ObjCRuntime.NativeHandle ClassHandle => class_ptr; | ||||||
|
|
||||||
| /// <summary>Creates a new <see cref="NSCodingSubclass" /> with default values.</summary> | ||||||
| [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||||||
| [DesignatedInitializer] | ||||||
| [Export ("init")] | ||||||
| public NSCodingSubclass () : base (global::Foundation.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"); | ||||||
| } | ||||||
|
|
||||||
| /// <summary>Constructor to call on derived classes to skip initialization and merely allocate the object.</summary> | ||||||
| /// <param name="t">Unused sentinel value, pass NSObjectFlag.Empty.</param> | ||||||
| /// <remarks> | ||||||
| /// <para> | ||||||
| /// This constructor should be called by derived classes when they completely construct the object in managed code and merely want the runtime to allocate and initialize the <see cref="Foundation.NSObject" />. | ||||||
| /// This is required to implement the two-step initialization process that Objective-C uses, the first step is to perform the object allocation, the second step is to initialize the object. | ||||||
| /// When developers invoke this constructor, they take advantage of a direct path that goes all the way up to <see cref="Foundation.NSObject" /> to merely allocate the object's memory and bind the Objective-C and C# objects together. | ||||||
| /// The actual initialization of the object is up to the developer. | ||||||
| /// </para> | ||||||
| /// <para> | ||||||
| /// This constructor is typically used by the binding generator to allocate the object, but prevent the actual initialization to take place. | ||||||
| /// Once the allocation has taken place, the constructor has to initialize the object. | ||||||
| /// With constructors generated by the binding generator this means that it manually invokes one of the "init" methods to initialize the object. | ||||||
| /// </para> | ||||||
| /// <para>It is the developer's responsibility to completely initialize the object if they chain up using this constructor chain.</para> | ||||||
| /// <para> | ||||||
| /// In general, if the developer's constructor invokes the corresponding base implementation, then it should also call an Objective-C init method. | ||||||
| /// If this is not the case, developers should instead chain to the proper constructor in their class. | ||||||
| /// </para> | ||||||
| /// <para> | ||||||
| /// The argument value is ignored and merely ensures that the only code that is executed is the construction phase is the basic <see cref="Foundation.NSObject" /> allocation and runtime type registration. | ||||||
| /// Typically the chaining would look like this: | ||||||
| /// </para> | ||||||
| /// <example> | ||||||
| /// <code lang="csharp lang-csharp"><![CDATA[ | ||||||
| /// // | ||||||
| /// // The NSObjectFlag constructor merely allocates the object and registers the C# class with the Objective-C runtime if necessary. | ||||||
| /// // No actual initXxx method is invoked, that is done later in the constructor | ||||||
| /// // | ||||||
| /// // This is taken from the iOS SDK's source code for the UIView class: | ||||||
| /// // | ||||||
| /// [Export ("initWithFrame:")] | ||||||
| /// public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty) | ||||||
| /// { | ||||||
| /// // Invoke the init method now. | ||||||
| /// var initWithFrame = new Selector ("initWithFrame:").Handle; | ||||||
| /// if (IsDirectBinding) { | ||||||
| /// Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_CGRect (this.Handle, initWithFrame, frame); | ||||||
| /// } else { | ||||||
| /// Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_CGRect (this.SuperHandle, initWithFrame, frame); | ||||||
| /// } | ||||||
| /// } | ||||||
| /// ]]></code> | ||||||
| /// </example> | ||||||
| /// </remarks> | ||||||
| [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||||||
| [EditorBrowsable (EditorBrowsableState.Advanced)] | ||||||
| protected NSCodingSubclass (global::Foundation.NSObjectFlag t) : base (t) {} | ||||||
|
|
||||||
| /// <summary>A constructor used when creating managed representations of unmanaged objects. Called by the runtime.</summary> | ||||||
| /// <param name="handle">Pointer (handle) to the unmanaged object.</param> | ||||||
| /// <remarks> | ||||||
| /// <para> | ||||||
| /// This constructor is invoked by the runtime infrastructure (<see cref="ObjCRuntime.Runtime.GetNSObject(System.IntPtr)" />) to create a new managed representation for a pointer to an unmanaged Objective-C object. | ||||||
| /// Developers should not invoke this method directly, instead they should call <see cref="ObjCRuntime.Runtime.GetNSObject(System.IntPtr)" /> as it will prevent two instances of a managed object pointing to the same native object. | ||||||
| /// </para> | ||||||
| /// </remarks> | ||||||
| [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||||||
| [EditorBrowsable (EditorBrowsableState.Advanced)] | ||||||
| protected internal NSCodingSubclass (global::ObjCRuntime.NativeHandle handle) : base (handle) {} | ||||||
|
|
||||||
| /// <summary>A constructor that initializes the object from the data stored in the unarchiver object.</summary> | ||||||
| /// <param name="coder">The unarchiver object.</param> | ||||||
| /// <remarks> | ||||||
| /// <para>This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization). This is part of the <see cref="Foundation.NSCoding" /> protocol.</para> | ||||||
| /// <para>If developers want to create a subclass of this object and continue to support deserialization from an archive, they should implement a constructor with an identical signature: taking a single parameter of type <see cref="Foundation.NSCoder" /> and decorate it with the <c>[Export("initWithCoder:"]</c> attribute.</para> | ||||||
| /// <para>The state of this object can also be serialized by using the <see cref="Foundation.INSCoding.EncodeTo" /> companion method.</para> | ||||||
| /// </remarks> | ||||||
| [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] | ||||||
| [DesignatedInitializer] | ||||||
| [EditorBrowsable (EditorBrowsableState.Advanced)] | ||||||
| [Export ("initWithCoder:")] | ||||||
| public NSCodingSubclass (NSCoder coder) : base (NSObjectFlag.Empty) | ||||||
| { | ||||||
| UIKit.UIApplication.EnsureUIThread (); | ||||||
|
|
||||||
| if (IsDirectBinding) { | ||||||
| InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, Selector.GetHandle ("initWithCoder:"), coder.Handle), "initWithCoder:"); | ||||||
| } else { | ||||||
| InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("initWithCoder::"), coder.Handle), "initWithCoder:"); | ||||||
|
||||||
| InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("initWithCoder::"), coder.Handle), "initWithCoder:"); | |
| InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("initWithCoder:"), coder.Handle), "initWithCoder:"); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inheriting from NSCoding doesn't make sense, we only care for classes that implement INSCoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's coming from the branch we depend. will update accordingly.