Exemplo n.º 1
0
        private string nonVoidFunction(Function func, string modName)
        {
            StringBuilder builder = new StringBuilder("");

            builder.Append(TAB + TAB + "public async Task<" + JSDocHelper.GetCSharpType(func.ReturnTypes[0]) + "> " + func.FuncName + "(");
            string prms = "";

            for (int i = 0; i < func.Parameters.Count; i++)
            {
                builder.Append(JSDocHelper.GetCSharpType(func.Parameters[i].ParameterTypes[0]));
                builder.Append(" " + func.Parameters[i].Name);
                prms += func.Parameters[i].Name;
                if (i != func.Parameters.Count - 1)
                {
                    builder.Append(" , ");
                    prms += ",";
                }
            }
            builder.Append(")" + EOL);
            builder.Append(TAB + TAB + "{" + EOL);
            builder.Append(TAB + TAB + TAB + "return await Runtime.InvokeAsync" + "<" + JSDocHelper.GetCSharpType(func.ReturnTypes[0]) + ">(" + "\"" + modName + "_" + func.FuncName + "\"" + ",");
            builder.Append(prms + ");" + EOL);
            builder.Append(TAB + TAB + "}" + EOL);

            /*"public async void AddData(object xs, object ys)
             * {
             *  await Runtime.InvokeVoidAsync("addDataML5", Hash, xs, ys);
             * }"*/

            return(builder.ToString());
        }
Exemplo n.º 2
0
 private void CreateProperty(JSDoc doc, StreamWriter writer)
 {
     foreach (var prop in doc.Properties)
     {
         writer.WriteLine("\t\t" + JSDocHelper.GetCSharpType(prop.DataTypes).PadRight(10) + " " + prop.Name + ";");
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            JSDocAnalyzer analyzer = new JSDocAnalyzer();
            List <JSDoc>  docs     = new List <JSDoc>();

            if (args.Length > 0)
            {
                docs = analyzer.Analyse(args[0]);
            }
            else
            {
                string root = AppDomain.CurrentDomain.BaseDirectory;
                root = Path.Combine(root, "dir");
                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory("dir");
                }
                docs = analyzer.Analyse(root, true);
            }

            GeneratorCSharp gen = new GeneratorCSharp();

            gen.BuildCSharpPage(docs.ToArray());
            GenerateJS genJs = new GenerateJS();

            genJs.BuildJS(docs.ToArray());

            foreach (var item in docs)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(item.FilePath);

                foreach (var p in item.Properties)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write(p.DataTypes);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("  " + p.Name + ";");
                }
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("func");
                foreach (var func in item.Functions)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    if (func.ReturnTypes.Count > 0)
                    {
                        Console.Write(JSDocHelper.GetCSharpType(func.ReturnTypes[0].ToLower()) + "  ");
                    }
                    else
                    {
                        Console.Write("void  ");
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write(func.FuncName);
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.Write('(');
                    for (int i = 0; i < func.Parameters.Count; i++)
                    {
                        if (i != func.Parameters.Count - 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write(func.Parameters[i].Name);
                            Console.Write(":");
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write(JSDocHelper.GetCSharpType(func.Parameters[i].ParameterTypes[0].ToLower()) + ",");
                        }
                        else if (i == func.Parameters.Count - 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write(func.Parameters[i].Name);
                            Console.Write(":");
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write(JSDocHelper.GetCSharpType(func.Parameters[i].ParameterTypes[0].ToLower()));
                            Console.ForegroundColor = ConsoleColor.DarkCyan;
                            Console.Write(")");
                        }
                    }
                    if (func.Parameters.Count == 0)
                    {
                        Console.Write(")");
                    }
                    Console.WriteLine(";");
                }
            }
        }