Skip to content

Instantly share code, notes, and snippets.

@jknopp
Forked from Ablecken/ValueInjecterExtensions
Created September 6, 2019 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jknopp/ba2cb47f959b79b422e51c0e2f3a1d27 to your computer and use it in GitHub Desktop.
Save jknopp/ba2cb47f959b79b422e51c0e2f3a1d27 to your computer and use it in GitHub Desktop.
ValueInjecter Create Type On Inject
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