Skip to content
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

[SwiftBindings] Made AnyType compatible with ISwiftObject #2909

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

stephen-hawley
Copy link

  • Moved SwiftOptional<T> to the Swift namespace.

  • Updated the AnyType class to be compatible with the ISwiftObject interface.

  • This change adds the methods NewFromPayload and MarshalToSwift to AnyObject.

Since the default implementation of GetTypeMetadata returns an invalid metadata, the MarshalToSwift method throws an exception.

Since the default implementation has a payload of SwiftHandle.Zero, MarshalToSwift throws an exception.

@stephen-hawley stephen-hawley added the area-SwiftBindings Swift bindings for .NET label Jan 6, 2025
var metadata = SwiftObjectHelper<AnyType>.GetTypeMetadata();
if (!metadata.IsValid)
{
throw new InvalidOperationException("Cannot marshal AnyType to Swift without metadata");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these strings be localized?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I put the exceptions in as an afterthought since it looks like this is not an actual valid type because of the lack of a valid TypeMetadata. @kotlarmilos - is AnyType a placeholder for the future since it isn't valid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- it is safe to assume the type is not valid.

var metadata = SwiftObjectHelper<AnyType>.GetTypeMetadata();
if (!metadata.IsValid)
{
throw new InvalidOperationException("Cannot marshal AnyType to Swift without metadata");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- it is safe to assume the type is not valid.

@kotlarmilos
Copy link
Member

This change breaks the compilation: The type or namespace name 'MetadataRequest' could not be found.

Copy link
Member

@jkurdek jkurdek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just get this to compile before merging

@stephen-hawley stephen-hawley merged commit b7670fa into feature/swift-bindings Jan 9, 2025
6 checks passed
@stephen-hawley stephen-hawley deleted the AnyType-fix branch January 9, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-SwiftBindings Swift bindings for .NET
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants