Beispiel #1
0
 public static void FromAssemblies(ICollection <string> assemblyPaths, WriterConfig config, TextWriter w)
 {
     foreach (var aPath in assemblyPaths)
     {
         FromAssembly(aPath, config, w);
     }
 }
Beispiel #2
0
 public CsWriter(WriterConfig config, TextWriter w, IEnumerable <string> supportedNamespaces)
 {
     _config = config;
     _w      = w;
     _supportedNamespaces = new HashSet <string>(supportedNamespaces)
     {
         "System",
         "System.Collections.Generic"
     };
 }
Beispiel #3
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 #4
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));
        }
Beispiel #5
0
 public static void FromAssembly(string assemblyPath, WriterConfig config, TextWriter w)
 {
     throw new NotImplementedException();
 }
Beispiel #6
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));
        }
Beispiel #7
0
        /// <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));
        }