Browse Source

Add System.Runtime.InteropServices.UnmanagedFunctionPointer

pull/4971/head
Nikita Tsukanov 5 years ago
parent
commit
96eaa26d1d
  1. 7
      src/tools/MicroComGenerator/CSharpGen.InterfaceGen.cs
  2. 7
      src/tools/MicroComGenerator/CSharpGen.cs
  3. 7
      src/tools/MicroComGenerator/Extensions.cs

7
src/tools/MicroComGenerator/CSharpGen.InterfaceGen.cs

@ -278,11 +278,12 @@ namespace MicroComGenerator
// Generate VTable method
var shadowDelegate = DelegateDeclaration(ParseTypeName(returnArg.NativeType), member.Name+"Delegate")
var shadowDelegate = DelegateDeclaration(ParseTypeName(returnArg.NativeType), member.Name + "Delegate")
.AddParameterListParameters(Parameter(Identifier("@this")).WithType(ParseTypeName("IntPtr")))
.AddParameterListParameters(args.Select(x =>
Parameter(Identifier(x.Name)).WithType(ParseTypeName(x.NativeType))).ToArray());
Parameter(Identifier(x.Name)).WithType(ParseTypeName(x.NativeType))).ToArray())
.AddAttribute("System.Runtime.InteropServices.UnmanagedFunctionPointer",
"System.Runtime.InteropServices.CallingConvention.StdCall");
var shadowMethod = MethodDeclaration(shadowDelegate.ReturnType, member.Name)
.WithParameterList(shadowDelegate.ParameterList)

7
src/tools/MicroComGenerator/CSharpGen.cs

@ -109,13 +109,8 @@ namespace MicroComGenerator
return ns.AddMembers(_idl.Structs.Select(e =>
StructDeclaration(e.Name)
.WithModifiers(TokenList(Token(_visibility)))
.AddAttribute("System.Runtime.InteropServices.StructLayout", "System.Runtime.InteropServices.LayoutKind.Sequential")
.AddModifiers(Token(SyntaxKind.UnsafeKeyword))
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(ParseName("System.Runtime.InteropServices.StructLayout"),
AttributeArgumentList(SingletonSeparatedList(
AttributeArgument(
ParseExpression("System.Runtime.InteropServices.LayoutKind.Sequential"))))
))))
.WithMembers(new SyntaxList<MemberDeclarationSyntax>(SeparatedList(e.Select(m =>
DeclareField(m.Type.ToString(), m.Name, SyntaxKind.PublicKeyword)))))
).ToArray());

7
src/tools/MicroComGenerator/Extensions.cs

@ -81,6 +81,13 @@ namespace MicroComGenerator
return cl.AddBaseListTypes(SimpleBaseType(SyntaxFactory.ParseTypeName(bt)));
}
public static T AddAttribute<T>(this T member, string attribute, params string[] args) where T : MemberDeclarationSyntax
{
return (T)member.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(ParseName(attribute), AttributeArgumentList(
SeparatedList(args.Select(a => AttributeArgument(ParseExpression(a)))))))));
}
public static string StripPrefix(this string s, string prefix) => string.IsNullOrEmpty(s)
? s
: s.StartsWith(prefix)

Loading…
Cancel
Save