aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual Studio/Tango.Protobuf/CompilerFileResult.cs
blob: 864c5f67ae46ff83bd983b0b3b4b66fe13e5f06c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Protobuf
{
    /// <summary>
    /// Represents an <see cref="IProtoCompiler"/> file compilation result.
    /// </summary>
    /// <seealso cref="Tango.Protobuf.ICompilerResult" />
    public class CompilerFileResult : ICompilerResult
    {
        /// <summary>
        /// Gets the compiled language.
        /// </summary>
        public CompilerLanguage Language { get; private set; }

        /// <summary>
        /// Gets the name of the file.
        /// </summary
        public String FileName { get; private set; }

        /// <summary>
        /// Gets the file path.
        /// </summary>
        public String FilePath { get; private set; }

        /// <summary>
        /// Gets the file content.
        /// </summary>
        public String Content { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerFileResult"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="content">The content.</param>
        /// <param name="language">The language.</param>
        public CompilerFileResult(String filePath, String content, CompilerLanguage language)
        {
            FilePath = filePath;
            FileName = Path.GetFileName(filePath);
            Content = content;
            Language = language;
        }

        /// <summary>
        /// Saves the result to the specified folder.
        /// </summary>
        /// <param name="folder">The folder.</param>
        public void Save(String folder)
        {
            Directory.CreateDirectory(folder);
            File.WriteAllText(Path.Combine(folder, FileName), Content);
        }
    }
}