Files
raven/server/AyaNova/DataList/DataListFactory.cs
2020-01-21 21:27:09 +00:00

71 lines
2.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace AyaNova.DataList
{
internal static class DataListFactory
{
// internal static IAyaDataList GetAyaDataList(string ListKey)
// {
// switch (ListKey)
// {
// case nameof(TestWidgetUserEmailDataList):
// return new TestWidgetUserEmailDataList();
// case nameof(WidgetDataList):
// return new WidgetDataList();
// default:
// throw new System.ArgumentOutOfRangeException($"DataListFactory: Unknown list \"{ListKey}\"");
// }
// }
// internal static List<string> DataListList = null;
// private static void PopulateDataListList(){
// DataListList= new List<string>();
// foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes)
// {
// if (ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
// {
// DataListList.Add(ti.Name);
// }
// }
// }
//This may be fast enough to not cache but let's see
internal static IAyaDataList GetAyaDataList(string ListKey)
{
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes)
{
// if (!ti.IsAbstract && ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
if(ti.Name==ListKey)
{
return ass.CreateInstance(ti.FullName) as IAyaDataList;
}
}
throw new System.ArgumentOutOfRangeException($"DEV ERROR in DataListFactory.cs: ListKey {ListKey} specified doesn't exist");
}
internal static List<string> GetListOfAllDataListKeyNames()
{
//https://stackoverflow.com/a/42574373/8939
List<string> ret = new List<string>();
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes)
{
if (ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
{
ret.Add(ti.Name);
}
}
return ret;
}
}//eoc
}//eons