Files
raven/server/AyaNova/DataList/DataListFactory.cs
2020-01-22 15:49:04 +00:00

40 lines
1.3 KiB
C#

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<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.IsAbstract && ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
{
ret.Add(ti.Name);
}
}
return ret;
}
}//eoc
}//eons