-
-
Save jknopp/ba2cb47f959b79b422e51c0e2f3a1d27 to your computer and use it in GitHub Desktop.
ValueInjecter Create Type On Inject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Omu.ValueInjecter; | |
namespace Infrastructure.Extensions | |
{ | |
public static class ValueInjecterExtensions | |
{ | |
/// <summary> | |
/// Will create a new instance of TResult, then inject from object | |
/// </summary> | |
/// <typeparam name="TResult">Type of object to create</typeparam> | |
/// <param name="from">Object to inject from</param> | |
/// <param name="injection">injection to use</param> | |
/// <returns></returns> | |
public static TResult InjectToType<TResult>(this object from, IValueInjection injection = null) | |
{ | |
if (from == null) throw new ArgumentNullException(); | |
IValueInjection inject = injection ?? new LoopInjection(); | |
return (TResult)Activator.CreateInstance(typeof(TResult)).InjectFrom(inject, from); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment