You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
959 B
37 lines
959 B
namespace Shared;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static U ToU<T, U>(this T t, GenericMapper<T, U> mapper, Func<T, U> func,Action<T, U>? action = null) where U :class where T :class
|
|
{
|
|
var res = mapper.GetU(t);
|
|
if (res != null) {
|
|
return res;
|
|
}
|
|
U u = func(t);
|
|
mapper.Add(t, u);
|
|
if(action != null) action(t, u);
|
|
return u;
|
|
}
|
|
// , Action<T, U> action
|
|
public static T ToT<T,U>(this U u, GenericMapper<T, U> mapper, Func<U, T> func,Action<U, T>? action = null) where U :class where T :class
|
|
{
|
|
var result = mapper.GetT(u);
|
|
|
|
if(result != null) return result;
|
|
|
|
T t = func(u);
|
|
mapper.Add(t, u);
|
|
if(action != null) action(u, t);
|
|
|
|
return t;
|
|
}
|
|
|
|
public static void AddRange<T>(this ICollection<T> set, IEnumerable<T> ts)
|
|
{
|
|
foreach(var t in ts)
|
|
{
|
|
set.Add(t);
|
|
}
|
|
}
|
|
} |