editorconfig and code cleanup
This commit is contained in:
@@ -367,8 +367,8 @@ public class DtsodV21 : Dictionary<string, dynamic>, IDtsod
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
void Debug(params string[] msg) => PublicLog.Log(msg);
|
||||
void DebugNoTime(params string[] msg) => PublicLog.LogNoTime(msg);
|
||||
static void Debug(params string[] msg) => PublicLog.Log(msg);
|
||||
static void DebugNoTime(params string[] msg) => PublicLog.LogNoTime(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
void Debug(params string[] msg) => PublicLog.Log(msg);
|
||||
void DebugNoTime(params string[] msg) => PublicLog.LogNoTime(msg);
|
||||
static void Debug(params string[] msg) => PublicLog.Log(msg);
|
||||
static void DebugNoTime(params string[] msg) => PublicLog.LogNoTime(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace DTLib.Dtsod;
|
||||
namespace DTLib.Dtsod;
|
||||
|
||||
public class DtsodDict<TKey, TVal> : IDictionary<TKey, TVal>
|
||||
{
|
||||
@@ -33,7 +31,7 @@ public class DtsodDict<TKey, TVal> : IDictionary<TKey, TVal>
|
||||
}
|
||||
public virtual void Append(ICollection<KeyValuePair<TKey, TVal>> anotherDtsod)
|
||||
{
|
||||
foreach (var pair in anotherDtsod)
|
||||
foreach (KeyValuePair<TKey, TVal> pair in anotherDtsod)
|
||||
Add(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
@@ -44,8 +42,8 @@ public class DtsodDict<TKey, TVal> : IDictionary<TKey, TVal>
|
||||
|
||||
|
||||
public int Count => baseDict.Count;
|
||||
public ICollection<TKey> Keys { get => baseDict.Keys; }
|
||||
public ICollection<TVal> Values { get => baseDict.Values; }
|
||||
public ICollection<TKey> Keys => baseDict.Keys;
|
||||
public ICollection<TVal> Values => baseDict.Values;
|
||||
public bool IsReadOnly { get; } = false;
|
||||
|
||||
public virtual void Clear() => baseDict.Clear();
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
|
||||
|
||||
public DtsodV30() : base() => UpdateLazy();
|
||||
public DtsodV30(IDictionary<string, dynamic> dict) : base(dict) => UpdateLazy();
|
||||
public DtsodV30(string serialized) : this() { Append(Deserialize(serialized)); }
|
||||
public DtsodV30(string serialized) : this() => Append(Deserialize(serialized));
|
||||
|
||||
#if DEBUG
|
||||
static void DebugLog(params string[] msg) => PublicLog.Log(msg);
|
||||
@@ -180,7 +180,7 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
|
||||
break;
|
||||
case ';': // один параметр
|
||||
case ',': // для листов
|
||||
var str = b.ToString();
|
||||
string str = b.ToString();
|
||||
b.Clear();
|
||||
// hardcoded "null" value
|
||||
return str == "null" ? (new object[] { null }) : (new object[] { str });
|
||||
@@ -220,7 +220,7 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
|
||||
|
||||
object CreateInstance(Type type, object[] ctor_args)
|
||||
{
|
||||
if (TypeHelper.BaseTypeConstructors.TryGetValue(type, out var ctor))
|
||||
if (TypeHelper.BaseTypeConstructors.TryGetValue(type, out Func<string, dynamic> ctor))
|
||||
return (object)ctor.Invoke((string)ctor_args[0]);
|
||||
else if (type.CustomAttributes.Any(a => a.AttributeType == typeof(DtsodSerializableAttribute)))
|
||||
return Activator.CreateInstance(type, ctor_args);
|
||||
@@ -243,22 +243,14 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
|
||||
return output;
|
||||
}
|
||||
|
||||
public override void Append(ICollection<KeyValuePair<string, dynamic>> anotherDtsod)
|
||||
{
|
||||
base.Append(anotherDtsod);
|
||||
//UpdateLazy();
|
||||
}
|
||||
public override void Append(ICollection<KeyValuePair<string, dynamic>> anotherDtsod) => base.Append(anotherDtsod);//UpdateLazy();
|
||||
|
||||
public override void Add(string key, dynamic value)
|
||||
{
|
||||
base.Add(key, (object)value);
|
||||
//UpdateLazy();
|
||||
}
|
||||
public override void Add(string key, dynamic value) => base.Add(key, (object)value);//UpdateLazy();
|
||||
|
||||
protected static string Serialize(IDictionary<string, dynamic> dtsod, ushort tabsCount = 0)
|
||||
{
|
||||
StringBuilder b = new();
|
||||
foreach (var pair in dtsod)
|
||||
foreach (KeyValuePair<string, dynamic> pair in dtsod)
|
||||
{
|
||||
Type type = pair.Value.GetType();
|
||||
b.Append(TypeHelper.TypeToString(type)).Append(':')
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public static class TypeHelper
|
||||
{
|
||||
static public readonly Dictionary<Type, Func<string, dynamic>> BaseTypeConstructors = new()
|
||||
public static readonly Dictionary<Type, Func<string, dynamic>> BaseTypeConstructors = new()
|
||||
{
|
||||
{ typeof(bool), (inp) => inp.ToBool() },
|
||||
{ typeof(char), (inp) => inp.ToChar() },
|
||||
@@ -20,7 +20,7 @@ public static class TypeHelper
|
||||
{ typeof(decimal), (inp) => inp.ToDecimal() }
|
||||
};
|
||||
|
||||
static public Dictionary<Type, string> BaseTypeNames = new()
|
||||
public static Dictionary<Type, string> BaseTypeNames = new()
|
||||
{
|
||||
{ typeof(bool), "bool" },
|
||||
{ typeof(char), "char" },
|
||||
@@ -38,12 +38,12 @@ public static class TypeHelper
|
||||
{ typeof(decimal), "decimal" }
|
||||
};
|
||||
|
||||
static public string TypeToString(Type t) =>
|
||||
BaseTypeNames.TryGetValue(t, out var name)
|
||||
public static string TypeToString(Type t) =>
|
||||
BaseTypeNames.TryGetValue(t, out string name)
|
||||
? name
|
||||
: t.AssemblyQualifiedName;
|
||||
|
||||
static public Type TypeFromString(string str) => str switch
|
||||
public static Type TypeFromString(string str) => str switch
|
||||
{
|
||||
"bool" => typeof(bool),
|
||||
"char" => typeof(char),
|
||||
|
||||
Reference in New Issue
Block a user