using System.Collections.Generic;
public static void Main()
Placeholder placeholder = new Placeholder(Guid.NewGuid());
var result = placeholder.BuildWrapper(Guid.NewGuid(), Guid.NewGuid());
Console.WriteLine($"is the first test valid? {typeof(Wrapper<Placeholder>) == result.GetType()}");
Placeholder placeholder2 = new Placeholder(Guid.NewGuid());
Helper helper1 = new Helper(placeholder, placeholder.GetType());
var result2 = new List<Helper>{helper1}.ToWrapper();
var firstResult = result2.First();
Console.WriteLine($"is the second test valid? {typeof(Wrapper<Placeholder>) == firstResult.GetType()}");
public static class HelperExtensions
public static T CastTo<T>(this object o) => (T)o;
public static List<Wrapper> ToWrapper(this IEnumerable<Helper> helperList)
List<Wrapper> wrapperResponseList = new List<Wrapper>();
foreach (var help in helperList)
var methodInfo = typeof(HelperExtensions).GetMethod(nameof(CastTo), BindingFlags.Static | BindingFlags.Public);
var genericArguments = new[]{help.Type};
var genericMethodInfo = methodInfo?.MakeGenericMethod(genericArguments);
var typedValue = genericMethodInfo?.Invoke(null, new[]{help.Obj});
var wrapper = typedValue.BuildWrapper(Guid.NewGuid(), Guid.NewGuid());
wrapperResponseList.Add(wrapper);
return wrapperResponseList;
public static Wrapper<T> BuildWrapper<T>(this T obj, Guid foo, Guid bar)
InnerWrapper<T> inner = new InnerWrapper<T>(obj, bar);
return new Wrapper<T>(foo, inner);
public Placeholder(Guid value)
public readonly object Obj;
public readonly Type Type;
public Helper(object obj, Type type)
public readonly Guid Foo;
public class Wrapper<T> : Wrapper
public readonly InnerWrapper<T> InnerWrapper;
public Wrapper(Guid foo, InnerWrapper<T> innerWrapper): base(foo)
InnerWrapper = innerWrapper;
public class InnerWrapper<T>
public readonly Guid Bar;
public readonly T Content;
public InnerWrapper(T content, Guid bar)