Ejemplo n.º 1
0
        private void WriteMethodMarshal(ManagedMethod method, int numParameters)
        {
            var    nativeMethod = method.Native;
            string methodName   = nativeMethod.IsConstructor ?
                                  $"{nativeMethod.Parent.FullyQualifiedName}" : $"{nativeMethod.Name}";

            var currentParams = method.Parameters.Take(numParameters);
            var paramStrings  = currentParams.Select(p =>
            {
                string marshal = BulletParser.GetTypeMarshalCppCli(p);
                if (!string.IsNullOrEmpty(marshal))
                {
                    return(marshal);
                }

                var paramType = p.Native.Type;
                if (paramType.IsBasic)
                {
                    return(p.Name);
                }

                string paramString = "";
                switch (paramType.Kind)
                {
                case TypeKind.Pointer:
                case TypeKind.LValueReference:
                    if (paramType.Kind == TypeKind.LValueReference)
                    {
                        // Dereference
                        paramString = "*";
                    }

                    if (paramType.Referenced.Target?.BaseClass != null)
                    {
                        // Cast native pointer from base class
                        paramString += $"({paramType.Referenced.FullName}*)";
                    }
                    break;
                }

                paramString += p.Name;
                if (paramType.Kind == TypeKind.Pointer && paramType.Referenced.Kind == TypeKind.Void)
                {
                    paramString += ".ToPointer()";
                }
                else
                {
                    paramString += "->_native";
                }
                return(paramString);
            });

            Write($"{methodName}(");
            string parameters = ListToLines(paramStrings, WriteTo.Source, 1);

            Write($"{parameters})");
        }
Ejemplo n.º 2
0
        void OutputMethodMarshal(MethodDefinition method, int numParameters)
        {
            if (method.IsConstructor)
            {
                SourceWrite(method.Parent.FullName);
            }
            else
            {
                SourceWrite(method.Name);
            }
            SourceWrite('(');
            for (int i = 0; i < numParameters; i++)
            {
                var    param   = method.Parameters[i];
                string marshal = BulletParser.GetTypeMarshalCppCli(param);
                if (!string.IsNullOrEmpty(marshal))
                {
                    SourceWrite(marshal);
                }
                else if (param.Type.IsBasic)
                {
                    SourceWrite(param.ManagedName);
                }
                else
                {
                    if (param.Type.IsPointer || param.Type.IsReference)
                    {
                        if (param.Type.IsReference)
                        {
                            // Dereference
                            SourceWrite('*');
                        }

                        if (param.Type.Referenced.Target != null &&
                            param.Type.Referenced.Target.BaseClass != null)
                        {
                            // Cast native pointer from base class
                            SourceWrite(string.Format("({0}*)", param.Type.Referenced.FullName));
                        }
                    }
                    SourceWrite(param.ManagedName);
                    if (param.Type.IsPointer && param.Type.ManagedName.Equals("void"))
                    {
                        SourceWrite(".ToPointer()");
                    }
                    else
                    {
                        SourceWrite("->_native");
                    }
                }

                // Any more parameters?
                if (i != numParameters - 1)
                {
                    if (_sourceLineLength >= LineBreakWidth)
                    {
                        SourceWriteLine(",");
                        WriteTabs(2, true);
                    }
                    else
                    {
                        SourceWrite(", ");
                    }
                }
            }
            SourceWrite(')');
        }