using System.Collections.Generic; using System.Linq; namespace AyaNova.DataList { internal static class DataListFactory { //Instantiate list object specified //this is safe as it's only attempting to load assemblies in the AyaNova.DataList namespace so can't attempt to instantiate some random object or nefarious object //returns null if doesn't exist internal static IAyaDataList GetAyaDataList(string ListKey) { System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly(); return ass.CreateInstance($"AyaNova.DataList.{ListKey}") as IAyaDataList; } //List all the datalist types available internal static List GetListOfAllDataListKeyNames() { //https://stackoverflow.com/a/42574373/8939 List ret = new List(); System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly(); foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes) { if (!ti.IsAbstract && ti.ImplementedInterfaces.Contains(typeof(IAyaDataList))) { ret.Add(ti.Name); } } return ret; } }//eoc }//eons