public IDoBadStuff Get() { IDoBadStuff test = null; GetDlls().ForEach(d => { try { foreach (Type t in Assembly.LoadFrom(d).GetTypes()) { if (typeof(IDoBadStuff) == t) { continue; } if (t.GetInterface(typeof(IDoBadStuff).FullName) is null) { continue; } test = (IDoBadStuff)Activator.CreateInstance(t); } } catch { } }); return(test); }
// Check wether a .dll file implementing IDoBadStuff is available // if its available, it replaces the default bad stuff object private void InitializeBadStuff() { try { DoBadStuff = InterfaceLoader.Get <IDoBadStuff>(true); if (DoBadStuff is null) { DoBadStuff = new DefaultBadStuff(); } } catch (Exception ex) { DoBadStuff = new DefaultBadStuff(); if (Configuration.DebugMode) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }