예제 #1
0
        /// <summary>
        /// Registers a namespace (and all its declarations) into the assembly.
        /// </summary>
        /// <param name="nsContext"></param>
        public void RegisterNamespace(NamespaceDeclarationSyntax nsContext)
        {
            var nsName = nsContext.Name.ToString();

            var a = new NetNamespace
            {
                Name             = nsName,
                TypeDeclarations = RoslynParserHelpers.GetNamespaceTypeDeclarations(nsContext)
            };

            NetAssembly.Namespaces.Add(a);
        }
예제 #2
0
파일: CsWriter.cs 프로젝트: inormis/cstsd
        public virtual string WriteNamespace(NetNamespace netModule)
        {
            var typeDeclarationsContent = string.Join(_config.NewLines(2), netModule.TypeDeclarations.Select(WriteType));

            var content = JoinNonEmpty(_config.NewLines(2), typeDeclarationsContent);

            if (!string.IsNullOrWhiteSpace(content))
            {
                content = content.Indent(_indent) + _config.NewLine;
            }

            var usingStrings = string.Join("\r\n", netModule.ImportNamespaces.Select(u => $"using {u};"));

            return(usingStrings + _config.NewLines(2) +
                   $@"namespace {netModule.Name}" + _config.NewLine +
                   @"{" + _config.NewLine +
                   content +
                   @"}");
        }
예제 #3
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));
        }