forked from SharpGenTools/SharpGenTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverloadBuilder.cs
More file actions
54 lines (46 loc) · 1.81 KB
/
Copy pathMethodOverloadBuilder.cs
File metadata and controls
54 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using SharpGen.Config;
using SharpGen.Model;
namespace SharpGen.Transform;
internal sealed class MethodOverloadBuilder
{
private readonly Ioc ioc;
public MethodOverloadBuilder(Ioc ioc)
{
this.ioc = ioc ?? throw new ArgumentNullException(nameof(ioc));
}
private GlobalNamespaceProvider GlobalNamespace => ioc.GlobalNamespace;
public CsMethod CreateInterfaceArrayOverload(CsMethod original)
{
// Create a new method and transforms all array of CppObject to InterfaceArray<CppObject>
var newMethod = (CsMethod)original.Clone();
foreach (var csParameter in newMethod.PublicParameters)
{
if (!csParameter.IsInInterfaceArrayLike)
continue;
csParameter.PublicType = new CsInterfaceArray(
(CsInterface) csParameter.PublicType,
GlobalNamespace.GetTypeName(WellKnownName.InterfaceArray)
);
csParameter.MarshalType = TypeRegistry.IntPtr;
}
return newMethod;
}
public CsMethod CreateRawPtrOverload(CsMethod original)
{
// Create private method with raw pointers for arrays, with all arrays as pure IntPtr
// In order to be able to generate method taking single element
var rawMethod = (CsMethod)original.Clone();
rawMethod.Visibility = Visibility.Private;
foreach (var csSubParameter in rawMethod.PublicParameters)
{
if (csSubParameter.IsArray || csSubParameter.IsInterface || csSubParameter.HasPointer)
{
csSubParameter.PublicType = csSubParameter.MarshalType = TypeRegistry.IntPtr;
csSubParameter.IsArray = false;
csSubParameter.Attribute = CsParameterAttribute.In;
}
}
return rawMethod;
}
}