Exemplo n.º 1
0
        public override void Export(TypeScriptDefContext context)
        {
            var res     = new StringBuilder();
            var imports = this.FirstAncestor <Namespace>().GetImportList();

            res.Append(string.Join(Environment.NewLine, imports));
            if (imports.Any())
            {
                res.AppendLine(Environment.NewLine);
            }

            res.Append("namespace ")
            .AppendLine(Super.FullName("."))
            .AppendLine("{");

            res.Append(this.ToString())
            .AppendLine("}");

            // Get the destination path (namespace structure)
            string path = Super.FullName("\\") + "\\";
            // Get the full relative file path
            string fullPath = context.OutputDirectory + path + this.Name + ".cs";

            // Split the full path
            string[] tmp = fullPath.Split('\\');
            // Remove the filename from the path
            tmp = tmp.Take(tmp.Count() - 1).ToArray();
            // If needed, create the destination folder
#if LOG_VERBOSE
            context.Logger.WriteMessage("enum: " + fullPath);
#endif
            Directory.CreateDirectory(string.Join("\\", tmp));

            File.WriteAllText(fullPath, Tool.ReIndent(res.ToString()));
            context.CurrentGeneratedFiles.Add(fullPath);
        }