예제 #1
0
        public static void FromControllerRoslyn(string textFilePath, string outputNamespace, WriterConfig config, TextWriter w)
        {
            var tc = new NetTsControllerConverter();

            var css = new RoslynTypeScanner(outputNamespace);

            css.RegisterCodeFile(textFilePath);

            var ww = new TsWriter(config, w, css.NetAssembly.Namespaces.Select(n => n.Name));

            w.Write(RenderingHelpers.GetHeader(new[] { outputNamespace }));

            var netClasses = css.NetAssembly.Namespaces.SelectMany(netNamespace => netNamespace.TypeDeclarations).OfType <NetClass>().ToList();

            var tsNamespace = new TsNamespace
            {
                Name = outputNamespace
            };

            foreach (var netClass in netClasses)
            {
                var module = tc.GetControllerTsModule(netClass);
                tsNamespace.Modules.Add(module);
            }

            w.Write(ww.WriteNamespace(tsNamespace, false));
        }
예제 #2
0
        public static void FromEnumRoslyn(IEnumerable <string> inputFiles, string outputNamespace, WriterConfig config, TextWriter w)
        {
            var tc = new NetTsPocoConverter();

            var css = new RoslynTypeScanner(outputNamespace);

            foreach (var filePath in inputFiles)
            {
                css.RegisterCodeFile(filePath);
            }

            var ww = new TsWriter(config, w, css.NetAssembly.Namespaces.Select(n => n.Name));

            w.Write(RenderingHelpers.GetHeader(new[] { outputNamespace }));

            var netEnums = css.NetAssembly.Namespaces.SelectMany(netNamespace => netNamespace.TypeDeclarations).OfType <NetEnum>().ToList();

            var tsNamespace = new TsNamespace
            {
                Name = outputNamespace
            };

            //write enums
            foreach (var netEnum in netEnums)
            {
                //var tsEnum = tc.GetTsEnum(netEnum);
                //tsEnum.IsPublic = true;

                tsNamespace.TypeDeclarations.Add(tc.GetTsEnum(netEnum));
            }

            w.Write(ww.WriteNamespace(tsNamespace, false));
        }
예제 #3
0
        public static void FromPocoRoslyn(IEnumerable <string> inputFiles, string outputNamespace, WriterConfig config, TextWriter w)
        {
            var tc = new NetTsPocoConverter();

            var css = new RoslynTypeScanner(outputNamespace);

            foreach (var filePath in inputFiles)
            {
                css.RegisterCodeFile(filePath);
            }

            var ww = new TsWriter(config, w, css.NetAssembly.Namespaces.Select(n => n.Name));

            w.Write(RenderingHelpers.GetHeader(new[] { outputNamespace }));

            var netClasses = css.NetAssembly.Namespaces.SelectMany(netNamespace => netNamespace.TypeDeclarations).OfType <NetClass>().ToList();

            var tsNamespace = new TsNamespace
            {
                Name = outputNamespace
            };

            //write classes as export interfaces
            foreach (var netClass in netClasses)
            {
                if (netClass.Attributes.All(a => a != "TsExport"))
                {
                    continue;
                }
                tsNamespace.TypeDeclarations.Add(tc.GetTsInterface(netClass));
            }

            w.Write(ww.WriteNamespace(tsNamespace, true));
        }