示例#1
0
        public virtual void Write(FileTemplate fileTemplate, IOutput output)
        {
            if (string.IsNullOrEmpty(fileTemplate.Name))
            {
                Logger.Trace("Empty file skipped");
                return;
            }
            if (fileTemplate.Header.Description != null)
            {
                AssemblyName assemblyName = (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName();
                fileTemplate.Header.Description = string.Format(fileTemplate.Header.Description, $"{assemblyName.Name} {assemblyName.Version}");
            }
            FileWriter writer = new FileWriter(this);

            this.WriteHeader(fileTemplate, writer);
            StaticFileTemplate staticFile = fileTemplate as StaticFileTemplate;

            if (staticFile == null)
            {
                this.WriteUsings(fileTemplate, writer);
                this.Write(fileTemplate.Namespaces, writer);
            }
            else
            {
                writer.Add(staticFile.Content, true);
            }
            string fileName = FileSystem.Combine(fileTemplate.RelativePath, this.FormatFileName(fileTemplate.Name, fileTemplate.IsInterface()));

            output.Write(fileName, writer.ToString());
        }