Skip to content

Commit edeea18

Browse files
authored
Merge pull request #28 from monkey0506/generic-marshalling
Implement generic marshalling type argument feature
2 parents 35ebfde + 8aed9c1 commit edeea18

24 files changed

+744
-735
lines changed

ClosedGenericInterceptor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ private string GetSourceText()
4848
}
4949
var method = InterceptsMethod;
5050
var typeParameters = Constants.InterceptorTypeParameters[method.ContainingInterface.Arity];
51-
typeParameters = typeParameters.Length != 0 ?
52-
$"<{typeParameters}>" :
53-
typeParameters;
51+
typeParameters = method.Arity != 0 ?
52+
$"<{typeParameters}, XMarshaller>" :
53+
typeParameters.Length != 0 ?
54+
$"<{typeParameters}>" :
55+
typeParameters;
5456
_ = sb.Append
5557
(
5658
$@"[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -60,7 +62,7 @@ public static {method.ContainingInterface.FullName} {method.Name}{typeParameters
6062
){Constants.InterceptorAntiConstraints[method.ContainingInterface.Arity]}
6163
{{"
6264
);
63-
if (ImplementationClass.Marshalling.StaticCallingConvention is not null)
65+
if (ImplementationClass.MarshalInfo.StaticCallingConvention is not null)
6466
{
6567
_ = sb.Append
6668
(

Constants.Actions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class Actions
2424
$"{RootNamespace}.INativeAction`13",
2525
$"{RootNamespace}.INativeAction`14",
2626
$"{RootNamespace}.INativeAction`15",
27-
$"{RootNamespace}.INativeAction`16",
27+
$"{RootNamespace}.INativeAction`16"
2828
];
2929

3030
public static readonly string[] QualifiedTypeParameters = Constants.QualifiedTypeParameters;

Constants.Funcs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ .. Constants.AntiConstraints.Skip(1)
3131
$"{RootNamespace}.INativeFunc`14",
3232
$"{RootNamespace}.INativeFunc`15",
3333
$"{RootNamespace}.INativeFunc`16",
34-
$"{RootNamespace}.INativeFunc`17",
34+
$"{RootNamespace}.INativeFunc`17"
3535
];
3636

3737
public static readonly string[] QualifiedTypeParameters =

Constants.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ internal static partial class Constants
6262

6363
public static readonly string[] InterceptorAntiConstraints =
6464
[
65-
.. AntiConstraints.Select(static x => x.Replace('T', 'X')),
66-
$"{AntiConstraint_T1_T16.Replace('T', 'X')}{NewLineIndent2}where X17 : allows ref struct"
65+
.. AntiConstraints.Select(static x => x.Replace(" where T", " where X").Replace('T', 'X')),
66+
$"{AntiConstraint_T1_T16.Replace(" where T", " where X")
67+
.Replace('T', 'X')}{NewLineIndent2}where X17 : allows ref struct"
6768
];
6869

6970
public static readonly string[] Arguments =
@@ -111,6 +112,9 @@ .. AntiConstraints.Select(static x => x.Replace('T', 'X')),
111112
public const string RootNamespace = "Monkeymoto.NativeGenericDelegates";
112113
public const string DeclarationsSourceFileName = RootNamespace + ".Declarations.g.cs";
113114

115+
public const string IMarshallerInterfaceName = "IMarshaller";
116+
public const string IMarshallerMetadataName = $"{RootNamespace}.{IMarshallerInterfaceName}`1";
117+
114118
/// <summary>
115119
/// Returns the total number of interfaces per category (Action or Func).
116120
/// </summary>

DelegateMarshalling.Parser.cs

Lines changed: 0 additions & 322 deletions
This file was deleted.

0 commit comments

Comments
 (0)