using System.Reflection; using System.Runtime.ExceptionServices; namespace Ariadne.UnitTests { /// /// Builds arcs from a save through their loading constructors, the way a save library does. /// public static class LoadedArc { public static ArcType From(IArcReader reader) { ConstructorInfo constructor = typeof(ArcType).GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, binder: null, types: new[] { typeof(IArcReader) }, modifiers: null); try { return (ArcType)constructor.Invoke(new object[] { reader }); } catch (TargetInvocationException exception) { ExceptionDispatchInfo.Capture(exception.InnerException).Throw(); throw; } } } }