this code works for me but there must be a better way to accomplish the same thing. The method Search exists in multiple namespaces. the correct namespace to use depends on code that is irrelevant just like some of the other code displayed. any thoughts on rewritting this better?
example namespaces used
MTG.Sites.Test1
MTG.Sites.Test2
static public async Task<List<Card>> Search(string sNamespace) { List<Card> rawCards = null; try { Type t = Assembly.GetExecutingAssembly().GetType($"MTG.Sites.{sNamespace}"); if (t != null) { dynamic classInstance = Activator.CreateInstance(t); rawCards = await classInstance.Search(httpClient); } } catch(Exception ex) { log.Error(ex); } return rawCards; }
the code i want to improve is the use of Assembly.GetExecutingAssembly().GetType("");