56 lines
2.0 KiB
C#
56 lines
2.0 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 IDataListProcessing GetAyaDataList(string ListKey, long translationId)
|
|
{
|
|
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
|
return ass.CreateInstance($"AyaNova.DataList.{ListKey}", false, System.Reflection.BindingFlags.Default, null, new object[] { translationId }, null, null) as IDataListProcessing;
|
|
|
|
}
|
|
|
|
//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(IDataListProcessing)))
|
|
{
|
|
ret.Add(ti.Name);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
//Verify listkey
|
|
internal static bool ListKeyIsValid(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(IDataListProcessing)))
|
|
{
|
|
if (ti.Name == listKey)
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
}//eoc
|
|
}//eons |