Пример #1
0
        private string GetNativeCallMehtodBody(CodeMethod caller, CodeField field, CodeType typeDecl)
        {
            var sb = new StringBuilder();

            sb.Append("fixed (").Append(typeDecl.Name).Append("* self = &this)\n{\n\t");
            if (caller.RetVal.Type != "void")
            {
                sb.Append("return ");
            }

            var argTypes = new List <string>();

            if (caller.HasThisArg)
            {
                argTypes.Add(typeDecl.Name + "*");
            }
            argTypes.AddRange(caller.Parameters.Select(arg => CSharpCodeGen.GetClrTypeName(arg.Type)));
            argTypes.Add(CSharpCodeGen.GetClrTypeName(caller.RetVal.Type));

            sb.Append("((delegate* unmanaged[Stdcall]<").Append(string.Join(", ", argTypes)).Append(">)");
            sb.Append(field.Name).Append(")(");
            var args = new List <string>();

            if (caller.HasThisArg)
            {
                args.Add("self");
            }
            args.AddRange(caller.Parameters.Select(arg => arg.Name));
            sb.Append(string.Join(", ", args));
            sb.Append(");");
            sb.Append("\n}");

            return(sb.ToString());
        }
Пример #2
0
        private string GetNativeDelegate(CodeMethod caller, CodeType typeDecl)
        {
            var sb = new StringBuilder();

            sb.Append("delegate* unmanaged[Stdcall]<");
            var args = new List <string>();

            if (caller.HasThisArg)
            {
                args.Add(typeDecl.Name + "*");
            }
            args.AddRange(caller.Parameters.Select(arg => CSharpCodeGen.GetClrTypeName(arg.Type)));
            args.Add(CSharpCodeGen.GetClrTypeName(caller.RetVal.Type));
            sb.Append(string.Join(", ", args));
            sb.Append(">");
            return(sb.ToString());
        }