private void WriteMethod(IndentedTextWriter writer, Method method)
        {
            string clientMethodName = method.Name.Replace(".", "_");

            writer.Write("def ");
            writer.Write(clientMethodName);
            writer.Write("(self");

            Parameter[] parameters = method.GetParameters();

            foreach (Parameter parameter in parameters)
            {
                writer.Write(", ");
                writer.Write(parameter.Name);
            }

            writer.WriteLine("):");
            writer.Indent++;

            if (method.Description.Length > 0)
            {
                // TODO: What to do if /* and */ appear in the summary?

                writer.Write(_docQuotes);
                writer.WriteLine(method.Description);
                writer.WriteLine(_docQuotes);
            }

            writer.Write("return self.__call('");
            writer.Write(method.Name);
            writer.Write("', (");

            foreach (Parameter parameter in parameters)
            {
                writer.Write(parameter.Name);
                writer.Write(", ");
            }

            writer.WriteLine("))");
            writer.Indent--;
            writer.WriteLine();
        }
        private static object ReadParameters(Method method, JsonReader reader, ImportContext importContext)
        {
            Debug.Assert(method != null);
            Debug.Assert(reader != null);
            Debug.Assert(importContext != null);

            reader.MoveToContent();

            Parameter[] parameters = method.GetParameters();

            if (reader.TokenClass == JsonTokenClass.Array)
            {
                reader.Read();
                ArrayList argList = new ArrayList(parameters.Length);

                // TODO: This loop could bomb when more args are supplied that parameters available.

                for (int i = 0; i < parameters.Length && reader.TokenClass != JsonTokenClass.EndArray; i++)
                    argList.Add(importContext.Import(parameters[i].ParameterType, reader));

                reader.StepOut();
                return argList.ToArray();
            }
            else if (reader.TokenClass == JsonTokenClass.Object)
            {
                reader.Read();
                JsonObject argByName = new JsonObject();

                while (reader.TokenClass != JsonTokenClass.EndObject)
                {
                    // TODO: Imporve this lookup.
                    // FIXME: Does not work when argument is positional.

                    Type parameterType = AnyType.Value;
                    string name = reader.ReadMember();

                    foreach (Parameter parameter in parameters)
                    {
                        if (parameter.Name.Equals(name))
                        {
                            parameterType = parameter.ParameterType;
                            break;
                        }
                    }

                    argByName.Put(name, importContext.Import(parameterType, reader));
                }

                reader.Read();
                return argByName;
            }
            else
            {
                return importContext.Import(reader);
            }
        }
示例#3
0
        private static void AddSignature(Control parent, Method method)
        {
            Control methodSignatureSpan = AddSpan(parent, "method-sig", null);
            AddSpan(methodSignatureSpan, "method-param-open", "(");

            Parameter[] parameters = method.GetParameters();
            foreach (Parameter parameter in parameters)
            {
                if (parameter.Position > 0)
                    AddSpan(methodSignatureSpan, "method-param-delim", ", ");

                AddSpan(methodSignatureSpan, "method-param", parameter.Name);
            }

            AddSpan(methodSignatureSpan, "method-param-close", ")");
        }