Bind.JavaSpecWriter.GenerateParameterString C# (CSharp) Method

GenerateParameterString() static private method

static private GenerateParameterString ( System.Function f, bool &valid ) : string
f System.Function
valid bool
return string
        static string GenerateParameterString(Function f, out bool valid)
        {
            if (f == null)
                throw new ArgumentNullException("f");

            valid = true;
            var sb = new StringBuilder();

            //if (f.TrimmedName == "ExtGetBufferPointer")
            //    Debugger.Break();

            if (f.Parameters.Count > 0)
            {
                foreach (var p in f.Parameters)
                {
                    if (p.Reference)
                    {
                        // Use a boxed type instead of primitives (i.e. "Byte" rather than "byte"), since
                        // the former are reference types. We don't need to do anything for regular reference
                        // types.
                        // Hack: we do this by upper-casing the first letter of the type. This should work for
                        // all primitive types, but won't work for enums and other reference types. In these
                        // cases, we'll just ignore the reference overload.
                        if (Char.IsLower(p.CurrentType[0]))
                        {
                            // Hack: Int -> Integer and Bool -> Boolean
                            if (p.CurrentType == "int")
                                sb.Append("Integer");
                            else if (p.CurrentType == "bool")
                                sb.Append("Boolean");
                            else
                                sb.Append(Char.ToUpper(p.CurrentType[0]) + p.CurrentType.Substring(1));
                        }
                        else
                        {
                            valid = false;
                            return String.Empty;
                        }
                    }
                    else if (p.Array > 0)
                    {
                        // Generic arrays are handled in the IntPtr case below.
                        if (p.Generic)
                        {
                            valid = false;
                            return String.Empty;
                        }

                        sb.Append(p.CurrentType);
                        for (int i = 0; i < p.Array; i++)
                            sb.Append("[]");
                    }
                    else if (p.Pointer > 0)
                    {
                        // Java does not support pointers
                        // Todo: maybe use one of the java.nio.* pointer classes?
                        valid = false;
                        return String.Empty;
                    }
                    else if (p.CurrentType == "IntPtr")
                    {
                        sb.Append("Buffer");
                    }
                    else
                    {
                        sb.Append(p.CurrentType);
                    }

                    sb.Append(" ");
                    sb.Append(p.Name);
                    sb.Append(", ");
                }

                if (f.Parameters.Count > 0)
                    sb.Remove(sb.Length - 2, 2);
            }

            return sb.ToString();
        }