Skip to content

Commit 97d3f8d

Browse files
committed
Skip delegate types with in, out or ref parameters
Fixes #110
1 parent f732560 commit 97d3f8d

File tree

6 files changed

+470
-490
lines changed

6 files changed

+470
-490
lines changed

Generator/Beyond.NET.CodeGenerator/Collectors/TypeCollector.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,25 @@ out string? unsupportedReason
499499
unsupportedReason = "Unsupported delegate paramter type";
500500
return false;
501501
}
502+
503+
if (delegateParameter.IsOut) {
504+
unsupportedReason = "Unsupported delegate paramter type: Has out parameters";
505+
return false;
506+
}
507+
508+
if (delegateParameter.IsIn) {
509+
unsupportedReason = "Unsupported delegate paramter type: Has in parameters";
510+
return false;
511+
}
512+
513+
if (!ExperimentalFeatureFlags.EnableByRefParametersInDelegates) {
514+
Type parameterType = delegateParameter.ParameterType;
515+
516+
if (parameterType.IsByRef) {
517+
unsupportedReason = "Unsupported delegate paramter type: Has ref parameters";
518+
return false;
519+
}
520+
}
502521
}
503522
}
504523
}
@@ -510,4 +529,4 @@ out string? unsupportedReason
510529

511530
return true;
512531
}
513-
}
532+
}

Samples/Beyond.NET.Sample.Managed/Source/DelegatesTest.cs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public enum StepMode
2727
Out,
2828
}
2929

30-
// TODO: Delegates with ref parameters
30+
// TODO: Delegates with ref, out, in parameters
3131
public static class DelegatesTest
3232
{
3333
public delegate int TransformIntDelegate(int i);
34-
// public delegate int TransformIntWithRefDelegate(ref int iRef);
34+
public delegate int TransformIntWithRefDelegate(ref int iRef);
35+
public delegate void TransformIntWithOutDelegate(int i, out int iOut);
3536
public delegate StepMode DebugEventHandler(object sender, StepMode stepMode);
3637

3738
public static int TransformInt(
@@ -44,18 +45,26 @@ TransformIntDelegate intTransformer
4445
return result;
4546
}
4647

47-
// public static int TransformIntWithRef(
48-
// ref int iRef,
49-
// TransformIntWithRefDelegate intTransformer
50-
// )
51-
// {
52-
// int result = intTransformer(ref iRef);
53-
//
54-
// return result;
55-
// }
48+
public static int TransformIntWithRef(
49+
ref int iRef,
50+
TransformIntWithRefDelegate intTransformer
51+
)
52+
{
53+
int result = intTransformer(ref iRef);
54+
55+
return result;
56+
}
57+
58+
public static void TransformIntWithOut(
59+
int i,
60+
TransformIntWithOutDelegate intTransformer
61+
)
62+
{
63+
intTransformer(i, out i);
64+
}
5665

5766
public delegate Point PointTransformDelegate(Point point);
58-
// public delegate Point PointTransformWithRefDelegate(ref Point pointRef);
67+
public delegate Point PointTransformWithRefDelegate(ref Point pointRef);
5968

6069
public static Point TransformPoint(
6170
Point point,
@@ -67,18 +76,18 @@ PointTransformDelegate pointTransformer
6776
return result;
6877
}
6978

70-
// public static Point TransformRefPoint(
71-
// ref Point pointRef,
72-
// PointTransformWithRefDelegate pointTransformer
73-
// )
74-
// {
75-
// Point result = pointTransformer(ref pointRef);
76-
//
77-
// return result;
78-
// }
79+
public static Point TransformRefPoint(
80+
ref Point pointRef,
81+
PointTransformWithRefDelegate pointTransformer
82+
)
83+
{
84+
Point result = pointTransformer(ref pointRef);
85+
86+
return result;
87+
}
7988

8089
public static StepMode TransformStepMode(StepMode mode)
8190
{
8291
return mode;
8392
}
84-
}
93+
}

Samples/Generated/Generated_C.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Number of generated types: 1638
1+
// Number of generated types: 1637
22
// Number of generated members: 7782
33

44
#pragma mark - BEGIN Header
@@ -2357,6 +2357,9 @@ typedef struct DNReadOnlySpanOfByte {
23572357
// Unsupported Type "System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]": Is Array of Generic Type
23582358
// Unsupported Type "System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]": Is Array of Generic Type
23592359
// Unsupported Type "Beyond.NET.Sample.IAnimal[]": Is Array of Interface Type
2360+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+TransformIntWithRefDelegate": Unsupported delegate paramter type: Has ref parameters
2361+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+TransformIntWithOutDelegate": Unsupported delegate paramter type: Has out parameters
2362+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+PointTransformWithRefDelegate": Unsupported delegate paramter type: Has ref parameters
23602363
// Unsupported Type "Converter`2": Is Generic Delegate Type
23612364
// Unsupported Type "System.Predicate`1[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
23622365
// Unsupported Type "System.Action`1[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
@@ -2387,6 +2390,8 @@ typedef struct DNReadOnlySpanOfByte {
23872390
// Unsupported Type "Beyond.NET.Sample.INotImplementedInterfaceWithStaticAbstractMembers": Static abstract members in interface
23882391
// Unsupported Type "System.Span`1[[System.Byte, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]&": Is unsupported Type
23892392
// Unsupported Type "System.Nullable`1": Excluded
2393+
// Unsupported Type "Beyond.NET.Sample.ByRefParametersDelegate": Unsupported delegate paramter type: Has ref parameters
2394+
// Unsupported Type "Beyond.NET.Sample.OutParametersDelegate": Unsupported delegate paramter type: Has out parameters
23902395
// Unsupported Type "System.ArraySegment`1[[System.Byte, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]&": Is unsupported Type
23912396
// Unsupported Type "System.Func`1[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
23922397
// Unsupported Type "System.Func`2[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
@@ -5594,6 +5599,7 @@ typedef void* Beyond_NET_Sample_Point_t;
55945599

55955600
typedef void* Beyond_NET_Sample_DelegatesTest_t;
55965601

5602+
55975603
typedef void* Beyond_NET_Sample_EventTests_t;
55985604

55995605
typedef void* Beyond_NET_Sample_GenericTestClass_A1_t;
@@ -6429,10 +6435,6 @@ typedef System_Byte_Array_t _Nullable (*Beyond_NET_Sample_SpanTest_SpanToByteArr
64296435

64306436
// TODO: (Beyond_NET_Sample_ByRefReturnValueDelegate) Unsupported delegate type. Reason: Has by ref return type
64316437

6432-
// TODO: (Beyond_NET_Sample_ByRefParametersDelegate) Unsupported delegate type. Reason: Has by ref parameters
6433-
6434-
// TODO: (Beyond_NET_Sample_OutParametersDelegate) Unsupported delegate type. Reason: Has out parameters
6435-
64366438
typedef void* Beyond_NET_Sample_CharReturnerDelegate_t;
64376439
typedef void (*Beyond_NET_Sample_CharReturnerDelegate_CDestructorFunction_t)(void* context);
64386440

@@ -45280,6 +45282,7 @@ Beyond_NET_Sample_DelegatesTest_Destroy(
4528045282

4528145283
#pragma mark - END APIs of Beyond.NET.Sample.DelegatesTest
4528245284

45285+
4528345286
#pragma mark - BEGIN APIs of Beyond.NET.Sample.EventTests
4528445287
Beyond_NET_Sample_EventTests_t _Nonnull /* Beyond.NET.Sample.EventTests */
4528545288
Beyond_NET_Sample_EventTests_Create(
@@ -63103,14 +63106,6 @@ Beyond_NET_Sample_SpanTest_SpanToByteArrayDelegate_Destroy(
6310363106
// TODO: (Beyond_NET_Sample_ByRefReturnValueDelegate_t) Unsupported delegate type. Reason: Has by ref return type
6310463107
#pragma mark - END APIs of Beyond.NET.Sample.ByRefReturnValueDelegate
6310563108

63106-
#pragma mark - BEGIN APIs of Beyond.NET.Sample.ByRefParametersDelegate
63107-
// TODO: (Beyond_NET_Sample_ByRefParametersDelegate_t) Unsupported delegate type. Reason: Has by ref parameters
63108-
#pragma mark - END APIs of Beyond.NET.Sample.ByRefParametersDelegate
63109-
63110-
#pragma mark - BEGIN APIs of Beyond.NET.Sample.OutParametersDelegate
63111-
// TODO: (Beyond_NET_Sample_OutParametersDelegate_t) Unsupported delegate type. Reason: Has out parameters
63112-
#pragma mark - END APIs of Beyond.NET.Sample.OutParametersDelegate
63113-
6311463109
#pragma mark - BEGIN APIs of Beyond.NET.Sample.CharReturnerDelegate
6311563110
Beyond_NET_Sample_CharReturnerDelegate_t _Nonnull /* Beyond.NET.Sample.CharReturnerDelegate */
6311663111
Beyond_NET_Sample_CharReturnerDelegate_Create(

Samples/Generated/Generated_CS.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22

3-
// Number of generated types: 1638
3+
// Number of generated types: 1637
44
// Number of generated members: 7782
55

66
// <Header>
@@ -3177,6 +3177,9 @@ internal static DNReadOnlySpanOfByte CopyToNativeReadOnlySpanOfByte(this ReadOnl
31773177
// Unsupported Type "System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]": Is Array of Generic Type
31783178
// Unsupported Type "System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]": Is Array of Generic Type
31793179
// Unsupported Type "Beyond.NET.Sample.IAnimal[]": Is Array of Interface Type
3180+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+TransformIntWithRefDelegate": Unsupported delegate paramter type: Has ref parameters
3181+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+TransformIntWithOutDelegate": Unsupported delegate paramter type: Has out parameters
3182+
// Unsupported Type "Beyond.NET.Sample.DelegatesTest+PointTransformWithRefDelegate": Unsupported delegate paramter type: Has ref parameters
31803183
// Unsupported Type "Converter`2": Is Generic Delegate Type
31813184
// Unsupported Type "System.Predicate`1[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
31823185
// Unsupported Type "System.Action`1[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
@@ -3207,6 +3210,8 @@ internal static DNReadOnlySpanOfByte CopyToNativeReadOnlySpanOfByte(this ReadOnl
32073210
// Unsupported Type "Beyond.NET.Sample.INotImplementedInterfaceWithStaticAbstractMembers": Static abstract members in interface
32083211
// Unsupported Type "System.Span`1[[System.Byte, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]&": Is unsupported Type
32093212
// Unsupported Type "System.Nullable`1": Excluded
3213+
// Unsupported Type "Beyond.NET.Sample.ByRefParametersDelegate": Unsupported delegate paramter type: Has ref parameters
3214+
// Unsupported Type "Beyond.NET.Sample.OutParametersDelegate": Unsupported delegate paramter type: Has out parameters
32103215
// Unsupported Type "System.ArraySegment`1[[System.Byte, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]&": Is unsupported Type
32113216
// Unsupported Type "System.Func`1[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
32123217
// Unsupported Type "System.Func`2[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]": Is Generic Delegate Type
@@ -159307,12 +159312,24 @@ internal unsafe class Beyond_NET_Sample_StepMode
159307159312

159308159313
internal unsafe class Beyond_NET_Sample_DelegatesTest
159309159314
{
159315+
// Unsupported Member "TransformIntWithRef": Has unsupported parameter(s): intTransformer: Unsupported delegate paramter type: Has ref parameters;
159316+
159317+
// Unsupported Member "TransformIntWithOut": Has unsupported parameter(s): intTransformer: Unsupported delegate paramter type: Has out parameters;
159318+
159319+
// Unsupported Member "TransformRefPoint": Has unsupported parameter(s): pointTransformer: Unsupported delegate paramter type: Has ref parameters;
159320+
159310159321
// Unsupported Member "TransformIntDelegate": Unsupported member type: NestedType
159311159322

159323+
// Unsupported Member "TransformIntWithRefDelegate": Unsupported member type: NestedType
159324+
159325+
// Unsupported Member "TransformIntWithOutDelegate": Unsupported member type: NestedType
159326+
159312159327
// Unsupported Member "DebugEventHandler": Unsupported member type: NestedType
159313159328

159314159329
// Unsupported Member "PointTransformDelegate": Unsupported member type: NestedType
159315159330

159331+
// Unsupported Member "PointTransformWithRefDelegate": Unsupported member type: NestedType
159332+
159316159333
[UnmanagedCallersOnly(EntryPoint = "Beyond_NET_Sample_DelegatesTest_TransformInt")]
159317159334
internal static int /* System.Int32 */ Beyond_NET_Sample_DelegatesTest_TransformInt(int /* System.Int32 */ i, void* /* Beyond.NET.Sample.DelegatesTest.TransformIntDelegate */ intTransformer, void** /* System.Exception */ __outException)
159318159335
{
@@ -159748,6 +159765,7 @@ private Beyond.NET.Sample.Point __InvokeByCallingCFunction(Beyond.NET.Sample.Poi
159748159765
}
159749159766

159750159767

159768+
159751159769
internal unsafe class Beyond_NET_Sample_EventTests
159752159770
{
159753159771
// Unsupported Member "add_ValueChanged": Is Special Name
@@ -169884,18 +169902,6 @@ internal unsafe class Beyond_NET_Sample_ByRefReturnValueDelegate
169884169902
}
169885169903

169886169904

169887-
internal unsafe class Beyond_NET_Sample_ByRefParametersDelegate
169888-
{
169889-
// TODO: Unsupported delegate type. Reason: Has by ref parameters
169890-
}
169891-
169892-
169893-
internal unsafe class Beyond_NET_Sample_OutParametersDelegate
169894-
{
169895-
// TODO: Unsupported delegate type. Reason: Has out parameters
169896-
}
169897-
169898-
169899169905
internal unsafe class Beyond_NET_Sample_CharReturnerDelegate
169900169906
{
169901169907
internal void* Context { get; }

0 commit comments

Comments
 (0)