예제 #1
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 +
                   @"}");
        }
예제 #2
0
        public virtual string WriteModule(TsModule netModule, bool isTopLevelDeclareNamespace)
        {
            var typeDeclarationsContent      = string.Join(_config.NewLines(2), netModule.TypeDeclarations.Select(WriteType));
            var functionDeclarationsContent  = string.Join(_config.NewLines(2), netModule.FunctionDeclarations.Select(fd => WriteMethod(fd, true)));
            var namespaceDeclarationsContent = string.Join(_config.NewLines(2), netModule.Namespaces.Select(ns => WriteNamespace(ns, false)));
            var fieldDeclarationsContent     = string.Join(_config.NewLines(2), netModule.FieldDeclarations.Select(fd => WriteFieldDeclaration(fd)));

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

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

            var declare = isTopLevelDeclareNamespace ? "declare " : "";
            var export  = netModule.IsExport ? "export " : "";

            return($@"{declare}{export}module {netModule.Name}" + _config.NewLine +
                   @"{" + _config.NewLine +
                   content +
                   @"}");
        }