chore: renamed parameter names for ISerializer methods
This commit is contained in:
@@ -4,15 +4,15 @@ namespace Engine.Core.Serialization;
|
|||||||
|
|
||||||
public interface ISerializer
|
public interface ISerializer
|
||||||
{
|
{
|
||||||
object Deserialize(string configuration);
|
object Deserialize(string content);
|
||||||
object Deserialize(string configuration, Type type);
|
object Deserialize(string content, Type type);
|
||||||
T Deserialize<T>(string configuration);
|
T Deserialize<T>(string content);
|
||||||
|
|
||||||
string Serialize(object instance);
|
string Serialize(object instance);
|
||||||
|
|
||||||
ProgressiveTask<object> DeserializeAsync(string configuration);
|
ProgressiveTask<object> DeserializeAsync(string content);
|
||||||
ProgressiveTask<object> DeserializeAsync(string configuration, Type type);
|
ProgressiveTask<object> DeserializeAsync(string content, Type type);
|
||||||
ProgressiveTask<T> DeserializeAsync<T>(string configuration);
|
ProgressiveTask<T> DeserializeAsync<T>(string content);
|
||||||
|
|
||||||
ProgressiveTask<string> SerializeAsync(object instance);
|
ProgressiveTask<string> SerializeAsync(object instance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
using Engine.Core.Config;
|
||||||
|
|
||||||
|
namespace Engine.Serializers.Yaml;
|
||||||
|
|
||||||
|
public class YamlConfiguration : BasicConfiguration
|
||||||
|
{
|
||||||
|
public readonly string FilePath;
|
||||||
|
|
||||||
|
private readonly YamlSerializer yamlSerializer = new();
|
||||||
|
|
||||||
|
public YamlConfiguration(string filePath)
|
||||||
|
{
|
||||||
|
if (!filePath.EndsWith(".yaml"))
|
||||||
|
filePath += ".yaml";
|
||||||
|
|
||||||
|
FilePath = filePath;
|
||||||
|
|
||||||
|
bool isRelativePath = Path.GetFullPath(filePath).CompareTo(filePath) != 0;
|
||||||
|
|
||||||
|
if (isRelativePath)
|
||||||
|
FilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath));
|
||||||
|
|
||||||
|
if (Path.GetDirectoryName(FilePath) is string directoryPath)
|
||||||
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
|
if (!File.Exists(FilePath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
string yamlFileText = File.ReadAllText(FilePath);
|
||||||
|
Dictionary<string, string> valuePairs = yamlSerializer.Deserialize<Dictionary<string, string>>(yamlFileText);
|
||||||
|
|
||||||
|
foreach ((string key, string value) in valuePairs)
|
||||||
|
Set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,65 +62,65 @@ public class YamlSerializer : Core.Serialization.ISerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Deserialize(string configuration)
|
public object Deserialize(string content)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
identifiableRegistry.Reset();
|
identifiableRegistry.Reset();
|
||||||
object result = deserializer.Deserialize(configuration)!;
|
object result = deserializer.Deserialize(content)!;
|
||||||
identifiableRegistry.AssignAll();
|
identifiableRegistry.AssignAll();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Deserialize(string configuration, Type type)
|
public object Deserialize(string content, Type type)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
identifiableRegistry.Reset();
|
identifiableRegistry.Reset();
|
||||||
object result = deserializer.Deserialize(configuration, type)!;
|
object result = deserializer.Deserialize(content, type)!;
|
||||||
identifiableRegistry.AssignAll();
|
identifiableRegistry.AssignAll();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Deserialize<T>(string configuration)
|
public T Deserialize<T>(string content)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
identifiableRegistry.Reset();
|
identifiableRegistry.Reset();
|
||||||
T result = deserializer.Deserialize<T>(configuration);
|
T result = deserializer.Deserialize<T>(content);
|
||||||
identifiableRegistry.AssignAll();
|
identifiableRegistry.AssignAll();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgressiveTask<object> DeserializeAsync(string configuration)
|
public ProgressiveTask<object> DeserializeAsync(string content)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
progressionTracker.Reset();
|
progressionTracker.Reset();
|
||||||
Task<object> task = Task.Run(() => Deserialize(configuration));
|
Task<object> task = Task.Run(() => Deserialize(content));
|
||||||
return new ProgressiveTask<object>(progressionTracker, task);
|
return new ProgressiveTask<object>(progressionTracker, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgressiveTask<object> DeserializeAsync(string configuration, Type type)
|
public ProgressiveTask<object> DeserializeAsync(string content, Type type)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
progressionTracker.Reset();
|
progressionTracker.Reset();
|
||||||
Task<object> task = Task.Run(() => Deserialize(configuration, type));
|
Task<object> task = Task.Run(() => Deserialize(content, type));
|
||||||
return new ProgressiveTask<object>(progressionTracker, task);
|
return new ProgressiveTask<object>(progressionTracker, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgressiveTask<T> DeserializeAsync<T>(string configuration)
|
public ProgressiveTask<T> DeserializeAsync<T>(string content)
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
progressionTracker.Reset();
|
progressionTracker.Reset();
|
||||||
Task<T> task = Task.Run(() => Deserialize<T>(configuration));
|
Task<T> task = Task.Run(() => Deserialize<T>(content));
|
||||||
return new ProgressiveTask<T>(progressionTracker, task);
|
return new ProgressiveTask<T>(progressionTracker, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,8 +135,8 @@ public class YamlSerializer : Core.Serialization.ISerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object InternalDeserialize(string configuration, Type type)
|
internal object InternalDeserialize(string content, Type type)
|
||||||
{
|
{
|
||||||
return deserializer.Deserialize(configuration, type)!;
|
return deserializer.Deserialize(content, type)!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user