Nerfed/Nerfed.Compiler/AssemblyDefinition.cs

64 lines
1.9 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace Nerfed.Compiler;
public class AssemblyDefinition
{
public string Name { get; set; }
public string Guid { get; set; }
//public bool IsEditor { get; set; }
// Add platform stuff here..?
// Add dll's here..?
// Add dependencies here..?
public static bool Create(string assemblyDefinitionFilePath, string name, out AssemblyDefinition assemblyDefinition)
{
assemblyDefinition = null;
if (File.Exists(assemblyDefinitionFilePath))
{
Console.WriteLine($"ERROR: File already exists!");
return false;
}
// Create project file.
assemblyDefinition = new AssemblyDefinition
{
Name = name,
Guid = System.Guid.NewGuid().ToString("B").ToUpper(),
};
Save(assemblyDefinition, assemblyDefinitionFilePath);
return true;
}
public static bool Save(AssemblyDefinition assemblyDefinition, string assemblyDefinitionFilePath)
{
string jsonString = JsonSerializer.Serialize(assemblyDefinition, AssemblyDefinitionContext.Default.AssemblyDefinition);
File.WriteAllText(assemblyDefinitionFilePath, jsonString);
return true;
}
public static bool Open(string assemblyDefinitionFilePath, out AssemblyDefinition assemblyDefinition)
{
string jsonString = File.ReadAllText(assemblyDefinitionFilePath);
assemblyDefinition = JsonSerializer.Deserialize(jsonString, AssemblyDefinitionContext.Default.AssemblyDefinition);
if (assemblyDefinition == null)
{
Console.WriteLine($"ERROR: Could not open {typeof(AssemblyDefinition)}.");
return false;
}
return true;
}
}
[JsonSerializable(typeof(AssemblyDefinition))]
public partial class AssemblyDefinitionContext : JsonSerializerContext
{
}