Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Apple.Core
{
/// <summary>
/// Attribute for manually specifying a class's corresponding Objective-C type name. This is required for classes
/// that do not share their C# type name with their Objective-C counterpart, such as nested classes.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class InteropTypeNameAttribute : Attribute
{
public string TypeName { get; private set; }

public InteropTypeNameAttribute(string customTypeName)
{
TypeName = customTypeName;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ protected static string GetInteropTypeName(Type type)
var typeName = type.Name;

// Special case for types that provide a custom interop type name.
if (type.GetProperty("InteropTypeName", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
?.GetValue(null) is string customTypeName)
if(type.GetCustomAttribute<InteropTypeNameAttribute>()?.TypeName is string customTypeName)
{
typeName = customTypeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public enum TimeScope : long
/// <summary>
/// Information about a single score by a player on a leaderboard.
/// </summary>
[InteropTypeName("GKLeaderboardEntry")]
[Introduced(iOS: "14.0", macOS: "11.0", tvOS: "14.0", visionOS: "1.0")]
public class Entry : NSObject
{
internal Entry(IntPtr pointer) : base(pointer) {}

// This allows interop to work with the Objective-C type which has a different name: GKLeaderboardEntry.
internal static string InteropTypeName => "GKLeaderboardEntry";

/// <summary>
/// An integer value that your game uses.
/// </summary>
Expand Down