Skip to content
Merged
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
46 changes: 11 additions & 35 deletions src/Mono.Android/Java.Interop/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,47 +453,23 @@ public static void RegisterType (string java_class, Type t)
}
}

static Dictionary<string, List<Converter<string, Type?>>>? packageLookup;

[MemberNotNull (nameof (packageLookup))]
static void LazyInitPackageLookup ()
{
if (packageLookup == null)
packageLookup = new Dictionary<string, List<Converter<string, Type?>>> (StringComparer.Ordinal);
}

const string TypeRegistrationNotSupported =
"Java package type registration is no longer supported. Java-to-managed type resolution now goes through the native and trimmable type maps.";

// The package-based Java-to-managed type registration fallback was removed
// (https://github.com/dotnet/android/issues/11663); type resolution now goes
// through the native / trimmable type map, and the generator no longer emits
// the `Java.Interop.__TypeRegistrations` class that called these methods. These
// shipped public APIs are retained for binary compatibility but now throw, as
// they can no longer register anything.
public static void RegisterPackage (string package, Converter<string, Type> lookup)
{
LazyInitPackageLookup ();

lock (packageLookup!) {
if (!packageLookup.TryGetValue (package, out var lookups))
packageLookup.Add (package, lookups = new List<Converter<string, Type?>> ());
lookups.Add (lookup);
}
throw new NotSupportedException (TypeRegistrationNotSupported);
}
Comment thread
simonrozsival marked this conversation as resolved.

public static void RegisterPackages (string[] packages, Converter<string, Type?>[] lookups)
{
LazyInitPackageLookup ();

if (packages == null)
throw new ArgumentNullException ("packages");
if (lookups == null)
throw new ArgumentNullException ("lookups");
if (packages.Length != lookups.Length)
throw new ArgumentException ("`packages` and `lookups` arrays must have same number of elements.");

lock (packageLookup!) {
for (int i = 0; i < packages.Length; ++i) {
string package = packages [i];
var lookup = lookups [i];

if (!packageLookup.TryGetValue (package, out var _lookups))
packageLookup.Add (package, _lookups = new List<Converter<string, Type?>> ());
_lookups.Add (lookup);
}
}
throw new NotSupportedException (TypeRegistrationNotSupported);
}

[Register ("mono/android/TypeManager", DoNotGenerateAcw = true)]
Expand Down
Loading