Document
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
namespace CLanguage.Syntax
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class Document
{
public readonly string Path;
public readonly string Content;
public readonly Encoding Encoding;
public bool IsCompilable {
get {
switch (System.IO.Path.GetExtension(Path).ToLowerInvariant()) {
case ".c":
case ".cpp":
case ".cxx":
case ".m":
case ".mpp":
case ".ino":
return true;
default:
return false;
}
}
}
public Document(string path, string content, Encoding encoding)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Document path must be specified", "path");
Path = path;
if (content == null)
throw new ArgumentNullException("content");
Content = content;
if (encoding == null)
throw new ArgumentNullException("encoding");
Encoding = encoding;
}
public Document(string path, string content)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Document path must be specified", "path");
Path = path;
if (content == null)
throw new ArgumentNullException("content");
Content = content;
Encoding = Encoding.UTF8;
}
public override string ToString()
{
return Path;
}
}
}