/// <summary> /// Injects values from source to target /// </summary> /// <param name="target">target where the value is going to be injected</param> /// <param name="injection">ValueInjection used</param> /// <param name="source">source from where the value is taken</param> /// <returns>the modified target</returns> public static object InjectFrom(this object target, IValueInjection injection, object source) { currentInjection = (IDeltaInjection)injection; target = injection.Map(source, target); return(target); }
public static TV Map <T, TV>(this T source, IValueInjection injection, Action <T, TV> itemFunc = null) where TV : class, new() { var dest = new TV(); if (source == null) { return(null); } if (injection != null) { dest.InjectFrom(injection, source); } else { dest.InjectFrom(source); } if (itemFunc != null) { itemFunc(source, dest); } return(dest); }
/// <summary> /// inject values from source to target /// </summary> /// <param name="injection">the injection used</param> /// <param name="target">target where the values is going to be injected</param> /// <param name="source">source from where the values are taken</param> /// <returns>the modified target</returns> public object Inject(IValueInjection injection, object target, params object[] source) { foreach (var o in source) { target = injection.Map(o, target); } return(target); }
/// <summary> /// Injects values from source to target /// </summary> /// <param name="target">target where the value is going to be injected</param> /// <param name="injection">ValueInjection used</param> /// <param name="source">source from where the value is taken</param> /// <returns>the modified target</returns> public static object InjectFrom(this object target, IValueInjection injection, params object[] source) { foreach (var o in source) { target = injection.Map(o, target); } return(target); }
/// <summary> /// Injection mapping with an Action to execute after injection /// </summary> /// <typeparam name="TS"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="itemFunc"></param> /// <param name="injection"></param> /// <returns></returns> public static T MapItem <TS, T>(this TS source, Action <TS, T> itemFunc, IValueInjection injection = null) where T : class, new() { var dest = source.MapItem <T>(injection); itemFunc(source, dest); return(dest); }
public static object Inject(this object to, object from, IValueInjection injection = null) { if (injection == null) { return(to.InjectFrom(from)); } return(to.InjectFrom(injection, from)); }
public static T Inject <T, V>(this T to, V from, IValueInjection injection = null) where V : class { if (injection == null) { return((T)to.InjectFrom(from)); } return((T)to.InjectFrom(injection, from)); }
public static T ConvertTo <T>(this object obj, IValueInjection injection = null) { var instance = Activator.CreateInstance <T>(); if (obj == null) { return(instance); } if (injection != null) { instance.InjectFrom(injection, obj); } else { instance.InjectFrom(obj); } return(instance); }
private static T GetInjectedInstance <TS, T>(TS source, IValueInjection injection) where T : new() { if (source == null) { return(default(T)); } var d = new T(); if (injection != null) { d.InjectFrom(injection, source); } else { d.InjectFrom(source); } return(d); }
/// <summary> /// Injects values from source to target /// </summary> /// <param name="target">target where the value is going to be injected</param> /// <param name="injection">ValueInjection used</param> /// <param name="source">source from where the value is taken</param> /// <returns>the modified target</returns> public static object InjectFrom(this object target, IValueInjection injection, object source) { target = injection.Map(source, target); return(target); }
/// <summary> /// Injection mapping for a collection with an Action to execute after injection /// </summary> /// <typeparam name="TS"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="itemFunc"></param> /// <param name="injection"></param> /// <returns></returns> public static IReadOnlyCollection <T> MapCollection <TS, T>(this IEnumerable <TS> source, Action <TS, T> itemFunc, IValueInjection injection = null) where T : new() { var dest = new List <T>(); // Null or empty just return empty list if (source == null || !source.Any()) { return(dest); } foreach (var s in source) { var d = GetInjectedInstance <TS, T>(s, injection); itemFunc(s, d); dest.Add(d); } return(dest); }
/// <summary> /// Basic injection mapping for a collection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="injection"></param> /// <returns></returns> public static IReadOnlyCollection <T> MapCollection <T>(this IEnumerable <object> source, IValueInjection injection = null) where T : new() { var dest = new List <T>(); // Null or empty just return empty list if (source == null || !source.Any()) { return(dest); } dest.AddRange(source.Select(s => GetInjectedInstance <object, T>(s, injection))); return(dest); }
public static IEnumerable <TV> MapEnumerable <T, TV, TArg>(this IEnumerable <T> source, IValueInjection injection, Action <T, TV, TArg> itemFunc = null, TArg arg = default(TArg)) where TV : new() { var dest = new List <TV>(); // Null or empty just return empty list if (source == null || !source.Any()) { return(null); } foreach (var s in source) { var d = new TV(); if (injection != null) { d.InjectFrom(injection, s); } else { d.InjectFrom(s); } if (itemFunc != null) { itemFunc(s, d, arg); } dest.Add(d); } return(dest); }
/// <summary> /// Basic injection mapping with specification of the destination type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="injection"></param> /// <returns></returns> public static T MapItem <T>(this object source, IValueInjection injection = null) where T : class, new() { return(GetInjectedInstance <object, T>(source, injection)); }