コード例 #1
0
        public void generate()
        {
            var root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"WebApi");
            var builder = new TypeScriptBuilder(root,"apiModule");
            builder.AddReference("typings/tsd.d.ts");

            var ts = builder.GenerateClientApi(typeof (RequestResponseController), "Demo.Api","http://demo/api/");
            Debug.WriteLine("File generated: {0}",(object)ts);
        }
コード例 #2
0
        private bool ProcessAssembly(string pathToAssembly, TypeScriptGeneratorOptions options)
        {
            if (!File.Exists(pathToAssembly))
            {
                Console.WriteLine("File {0} not found", pathToAssembly);
                return false;
            }

            Console.WriteLine("Processing {0}", pathToAssembly);

            try
            {
                var controllers = LoadControllers(pathToAssembly);

                if (!controllers.Any())
                {
                    Console.WriteLine("No controllers found");
                    return false;
                }

                foreach (var controller in controllers)
                {
                    Console.WriteLine("...analyzing {0}", controller.FullName);
                    try
                    {
                        var builder = new TypeScriptBuilder(options.DestFolder, options.NgModule);
                        foreach (var reference in options.References)
                        {
                            builder.AddReference(reference);
                        }

                        var pathToTs = builder.GenerateClientApi(controller, options.Namespace, options.ApiRoot);
                        Console.WriteLine("...written {0}", pathToTs);
                    }
                    catch (Exception ex)
                    {
                        DumpError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is ReflectionTypeLoadException)
                {
                    var typeLoadException = ex as ReflectionTypeLoadException;
                    var loaderExceptions = typeLoadException.LoaderExceptions;
                    foreach (var le in loaderExceptions)
                    {
                        DumpError(le);
                    }
                }
                else
                {
                    DumpError(ex);
                }
                return false;
            }

            return true;
        }