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.
28 lines
727 B
28 lines
727 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) where U :class where T :class
|
|
{
|
|
var u = mapper.GetU(t);
|
|
if (u != null) {
|
|
return u;
|
|
}
|
|
u = func(t);
|
|
mapper.Add(t, u);
|
|
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<T, U> action) where U :class where T :class
|
|
{
|
|
var t = mapper.GetT(u);
|
|
if (t != null) {
|
|
return t;
|
|
}
|
|
t = func(u);
|
|
mapper.Add(t, u);
|
|
action(t, u);
|
|
return t;
|
|
}
|
|
} |