2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-01-09 19:00:23 +00:00
This commit is contained in:
2025-12-04 17:23:19 +03:00
parent fadac3bd30
commit 8172bf0ba2

View File

@@ -71,7 +71,7 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
(Func<KeyValuePair<KT, VT>, KeyValuePair<NewKeyType, NewValueType>> selector) (Func<KeyValuePair<KT, VT>, KeyValuePair<NewKeyType, NewValueType>> selector)
{ {
var rt = new Map<NewKeyType, NewValueType>(); var rt = new Map<NewKeyType, NewValueType>();
foreach(var kv in dic) foreach (var kv in dic)
{ {
var nt = selector(kv); var nt = selector(kv);
rt.dic.Add(nt.Key, nt.Value); rt.dic.Add(nt.Key, nt.Value);
@@ -94,7 +94,7 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
return rt.TrimEnd('\r', '\n'); return rt.TrimEnd('\r', '\n');
} }
public Map(Map<KT,VT> source) public Map(Map<KT, VT> source)
{ {
dic = source.dic; dic = source.dic;
} }
@@ -103,7 +103,7 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
} }
public static Map<KT,VT> FromMap(Map<KT,VT> source, Type destinationType) public static Map<KT, VT> FromMap(Map<KT, VT> source, Type destinationType)
{ {
var rt = Activator.CreateInstance(destinationType) as Map<KT, VT>; var rt = Activator.CreateInstance(destinationType) as Map<KT, VT>;
rt.dic = source.dic; rt.dic = source.dic;
@@ -127,11 +127,18 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
return rt; return rt;
} }
public static Map<string,object> FromObject(object obj) public static Map<KT, VT> FromDictionary(Dictionary<KT, VT> source)
{
var rt = new Map<KT, VT>();
rt.dic = source;
return rt;
}
public static Map<string, object> FromObject(object obj)
{ {
var type = obj.GetType(); var type = obj.GetType();
var st = new Map<string,object>(); var st = new Map<string, object>();
var pi = type.GetTypeInfo().GetProperties().Where(x => x.CanRead); var pi = type.GetTypeInfo().GetProperties().Where(x => x.CanRead);
foreach (var p in pi) foreach (var p in pi)
@@ -225,7 +232,7 @@ public class Map<KT, VT> : IEnumerable<KeyValuePair<KT, VT>>, IMap
public object[] Serialize() public object[] Serialize()
{ {
var rt = new List<object>(); var rt = new List<object>();
foreach(var kv in dic) foreach (var kv in dic)
{ {
rt.Add(kv.Key); rt.Add(kv.Key);
rt.Add(kv.Value); rt.Add(kv.Value);