Skip to content

Commit

Permalink
fix: [macOS] Add NativeCtorGenerator support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 2, 2020
1 parent bc2841f commit 210b30b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public override void Execute(SourceGeneratorContext context)
private class SerializationMethodsGenerator : SymbolVisitor
{
private readonly SourceGeneratorContext _context;
private readonly Compilation _comp;
private readonly INamedTypeSymbol _iosViewSymbol;
private readonly Compilation _comp;
private readonly INamedTypeSymbol _iosViewSymbol;
private readonly INamedTypeSymbol _macosViewSymbol;
private readonly INamedTypeSymbol _androidViewSymbol;
private readonly INamedTypeSymbol _intPtrSymbol;
private readonly INamedTypeSymbol _jniHandleOwnershipSymbol;
Expand All @@ -39,7 +40,7 @@ private class SerializationMethodsGenerator : SymbolVisitor
namespace {0}
{{
#if __IOS__
#if __IOS__ || __MACOS__
[global::Foundation.Register]
#endif
partial class {1}
Expand All @@ -58,7 +59,7 @@ partial class {1}
/// </remarks>
public {3}(IntPtr javaReference, global::Android.Runtime.JniHandleOwnership transfer) : base (javaReference, transfer) {{ }}
#endif
#if __IOS__
#if __IOS__ || __MACOS__
/// <summary>
/// Native constructor, do not use explicitly.
/// </summary>
Expand All @@ -79,6 +80,7 @@ public SerializationMethodsGenerator(SourceGeneratorContext context)
_comp = context.Compilation;

_iosViewSymbol = context.Compilation.GetTypeByMetadataName("UIKit.UIView");
_macosViewSymbol = context.Compilation.GetTypeByMetadataName("AppKit.NSView");
_androidViewSymbol = context.Compilation.GetTypeByMetadataName("Android.Views.View");
_intPtrSymbol = context.Compilation.GetTypeByMetadataName("System.IntPtr");
_jniHandleOwnershipSymbol = context.Compilation.GetTypeByMetadataName("Android.Runtime.JniHandleOwnership");
Expand Down Expand Up @@ -117,10 +119,11 @@ public override void VisitNamespace(INamespaceSymbol symbol)
private void ProcessType(INamedTypeSymbol typeSymbol)
{
var isiOSView = typeSymbol.Is(_iosViewSymbol);
var ismacOSView = typeSymbol.Is(_macosViewSymbol);
var isAndroidView = typeSymbol.Is(_androidViewSymbol);
var smallSymbolName = typeSymbol.ToString().Replace(typeSymbol.ContainingNamespace + ".", "");

if (isiOSView)
if (isiOSView || ismacOSView)
{
var nativeCtor = typeSymbol
.GetMethods()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if XAMARIN_IOS
using Windows.UI.Core;
using Windows.UI.Core;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down Expand Up @@ -47,5 +46,4 @@ internal static void RequestCollect()
}
}
}
}
#endif
}

0 comments on commit 210b30b

Please sign in to comment.