diff --git a/server/AyaNova/DataList/AyaDataList.cs b/server/AyaNova/DataList/AyaDataList.cs index fa6fdf33..fb392ff5 100644 --- a/server/AyaNova/DataList/AyaDataList.cs +++ b/server/AyaNova/DataList/AyaDataList.cs @@ -13,7 +13,7 @@ namespace AyaNova.DataList internal abstract class AyaDataList : IAyaDataList { - internal AyaDataList() + public AyaDataList() { } diff --git a/server/AyaNova/DataList/DataListFactory.cs b/server/AyaNova/DataList/DataListFactory.cs index 46f09b57..2417d7d0 100644 --- a/server/AyaNova/DataList/DataListFactory.cs +++ b/server/AyaNova/DataList/DataListFactory.cs @@ -7,20 +7,51 @@ 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 DataListList = null; + + // private static void PopulateDataListList(){ + // DataListList= new List(); + // 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) { - switch (ListKey) - { - case nameof(TestWidgetUserEmailDataList): - return new TestWidgetUserEmailDataList(); - default: - throw new System.ArgumentOutOfRangeException($"DataListFactory: Unknown list \"{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 GetListOfAllDataListKeyNames() { + //https://stackoverflow.com/a/42574373/8939 List ret = new List(); System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly(); @@ -33,7 +64,6 @@ namespace AyaNova.DataList } } return ret; - } diff --git a/server/AyaNova/DataList/WidgetDataList.cs b/server/AyaNova/DataList/WidgetDataList.cs index f0642d5b..aa73e5ca 100644 --- a/server/AyaNova/DataList/WidgetDataList.cs +++ b/server/AyaNova/DataList/WidgetDataList.cs @@ -14,7 +14,7 @@ namespace AyaNova.DataList //NOTE: Due to the join, all the sql id and name fields that can conflict with the joined (in this case User) table need to be specified completely FieldDefinitions = new List(); - FieldDefinitions.Add(new AyaDataListFieldDefinition { LtKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" }); + FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" }); FieldDefinitions.Add(new AyaDataListFieldDefinition { LtKey = "WidgetName",