コード例 #1
0
    public override IEnumerable <MemberDeclarationSyntax> GenerateCode(
        CsFunction csElement, PlatformDetectionType platform)
    {
        var sig = csElement.InteropSignatures[platform];

        yield return(MethodDeclaration(
                         sig.ReturnTypeSyntax,
                         $"{csElement.CppElementName}{GeneratorHelpers.GetPlatformSpecificSuffix(platform)}"
                         )
                     .WithModifiers(ModifierList)
                     .WithAttributeLists(
                         SingletonList(
                             AttributeList(
                                 SingletonSeparatedList(
                                     Attribute(
                                         DllImportName)
                                     .WithArgumentList(
                                         AttributeArgumentList(
                                             SeparatedList(
                                                 new[]
        {
            AttributeArgument(IdentifierName(csElement.DllName)),
            AttributeArgument(
                LiteralExpression(
                    SyntaxKind.StringLiteralExpression,
                    Literal(csElement.CppElementName)))
            .WithNameEquals(
                NameEquals(IdentifierName("EntryPoint"))),
            AttributeArgument(
                ModelUtilities
                .GetManagedCallingConventionExpression(
                    csElement.CppCallingConvention))
            .WithNameEquals(
                NameEquals(IdentifierName("CallingConvention")))
        })))))))
                     .WithParameterList(
                         ParameterList(
                             SeparatedList(
                                 sig.ParameterTypes.Select(
                                     param => Parameter(Identifier(param.Name))
                                     .WithType(param.InteropTypeSyntax)))))
                     .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)));
    }