/// <summary> /// Instantiate an emulator core /// </summary> public IEmulator Create(ICoreInventoryParameters cip) { if (_useCoreLoadParameters) { var paramType = typeof(CoreLoadParameters <,>).MakeGenericType(new[] { SettingsType, SyncSettingsType }); // TODO: clean this up dynamic param = Activator.CreateInstance(paramType); param.Comm = cip.Comm; param.Game = cip.Game; param.Settings = (dynamic)cip.FetchSettings(Type, SettingsType); param.SyncSettings = (dynamic)cip.FetchSyncSettings(Type, SyncSettingsType); param.Roms = cip.Roms; param.Discs = cip.Discs; param.DeterministicEmulationRequested = cip.DeterministicEmulationRequested; return((IEmulator)CTor.Invoke(new object[] { param })); } else { // cores using the old constructor parameters can only take a single rom, so assume that here object[] o = new object[_paramMap.Count]; Bp(o, "comm", cip.Comm); Bp(o, "game", cip.Game); Bp(o, "rom", cip.Roms[0].RomData); Bp(o, "file", cip.Roms[0].FileData); Bp(o, "deterministic", cip.DeterministicEmulationRequested); Bp(o, "settings", cip.FetchSettings(Type, SettingsType)); Bp(o, "syncsettings", cip.FetchSyncSettings(Type, SyncSettingsType)); Bp(o, "extension", cip.Roms[0].Extension); return((IEmulator)CTor.Invoke(o)); } }
private IEmulator CreateUsingLegacyConstructorParameters(ICoreInventoryParameters cip) { // cores using the old constructor parameters can only take a single rom, so assume that here object[] o = new object[_paramMap.Count]; Bp(o, "comm", cip.Comm); Bp(o, "game", cip.Game); Bp(o, "rom", cip.Roms[0].RomData); Bp(o, "file", cip.Roms[0].FileData); Bp(o, "deterministic", cip.DeterministicEmulationRequested); Bp(o, "settings", cip.FetchSettings(Type, SettingsType)); Bp(o, "syncsettings", cip.FetchSyncSettings(Type, SyncSettingsType)); Bp(o, "extension", cip.Roms[0].Extension); return((IEmulator)CTor.Invoke(o)); }
private IEmulator CreateUsingCoreLoadParameters(ICoreInventoryParameters cip) { var paramType = typeof(CoreLoadParameters <,>).MakeGenericType(SettingsType, SyncSettingsType); // TODO: clean this up dynamic param = Activator.CreateInstance(paramType); param.Comm = cip.Comm; param.Game = cip.Game; param.Settings = (dynamic)cip.FetchSettings(Type, SettingsType); param.SyncSettings = (dynamic)cip.FetchSyncSettings(Type, SyncSettingsType); param.Roms = cip.Roms; param.Discs = cip.Discs; param.DeterministicEmulationRequested = cip.DeterministicEmulationRequested; return((IEmulator)CTor.Invoke(new object[] { param })); }
/// <summary> /// Instantiate an emulator core /// </summary> public IEmulator Create(ICoreInventoryParameters cip) { try { return(_useCoreLoadParameters ? CreateUsingCoreLoadParameters(cip) : CreateUsingLegacyConstructorParameters(cip)); } catch (TargetInvocationException e) { // When an exception occurs inside ConstructorInfo.Invoke, // we always want to expose the exception the core actually threw, // and not the implementation detail that reflected construction was used. ExceptionDispatchInfo.Capture(e.InnerException).Throw(); throw; // Needed only for flow analysis -- CSC doesn't know that ExceptionDispatchInfo.Throw() never returns } }