예제 #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));
        }
예제 #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));
        }
예제 #3
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));
        }
예제 #4
0
파일: RenderCs.cs 프로젝트: inormis/cstsd
        /// <summary>
        ///
        /// </summary>
        /// <param name="textFilePath">Input .cs file</param>
        /// <param name="outputNamespace"></param>
        /// <param name="config"></param>
        /// <param name="w"></param>
        public static void FromControllerRoslyn(string textFilePath, string outputNamespace, WriterConfig config, TextWriter w)
        {
            // gather types using Roslyn: register files to the type scanner
            var css = new RoslynTypeScanner(outputNamespace);

            css.RegisterCodeFile(textFilePath);


            // write header to text stream
            w.Write(RenderingHelpers.GetHeader(new[] { outputNamespace }));

            // get classes
            var netClasses = css.NetAssembly.Namespaces.SelectMany(nn => nn.TypeDeclarations).OfType <NetClass>().ToList();

            //class that converts net types to CS proxies
            var tc = new NetCsControllerConverter();

            // create a new CS namespace for our proxy classes
            var netNamespace = new NetNamespace
            {
                Name             = outputNamespace,
                ImportNamespaces = new[]
                {
                    "System",
                    "System.Collections.Generic",
                    "RestSharp",
                    "PowerServices.Core"
                }
            };

            //add each class to the namespace
            foreach (var netClass in netClasses)
            {
                var a = tc.GetControllerApiClientCsClass(netClass);
                netNamespace.TypeDeclarations.Add(a);
            }

            // this will write our CS types
            var ww = new CsWriter(config, w, css.NetAssembly.Namespaces.Select(n => n.Name));

            w.Write(ww.WriteNamespace(netNamespace));
        }