Beispiel #1
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));
        }
Beispiel #2
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));
        }