refactor: Use generic collections in PrimitiveManager

The class that instantiates ViewStreams via reflection
This commit is contained in:
John Colvin committed 2024-11-26 18:53:32 +00:00
1 parent baa9dbfe76
commit 3619d4b22c
2 files changed
+11 -15

No files matched your search

@@ -8,11 +8,12 @@ namespace BCG {
using System.Collections;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
public class PrimitiveManager {
private IDictionary myTypeLookupTable = new Hashtable();
private static PrimitiveManager mySelf;
private ArrayList myAssemblyNames = new ArrayList();
readonly List<string> myAssemblyNames = new();
readonly Dictionary<string, Type> myTypeLookupTable = new();
private PrimitiveManager() {
myLoadAllTypes();
@@ -95,15 +96,14 @@ namespace BCG {
}
/// <summary>
/// Returns the Type name corresponding to the primitive name
/// Returns the Type corresponding to the primitive name
/// </summary>
/// <param name="friendlyName"></param>
/// <returns></returns>
public string find(string friendlyName) {
if (myTypeLookupTable[friendlyName] == null)
throw new ApplicationException(friendlyName + " is not the friendly name of any of the loaded types");
return (myTypeLookupTable[friendlyName] as Type).Name;
}
public Type find(string friendlyName) =>
myTypeLookupTable.TryGetValue(friendlyName, out var t)
? t
: throw new ArgumentException($"'{friendlyName}' is not the friendly name of any of the loaded types", nameof(friendlyName));
/// <summary>
/// Constructs and returns a ViewStream of type corresponding to the friendly name
@@ -118,12 +118,8 @@ namespace BCG {
constructorArgs = new object[args.Count];
args.CopyTo(constructorArgs, 0);
}
if (myTypeLookupTable[friendlyName] == null)
throw new ApplicationException(friendlyName + " is not the friendly name of any of the loaded types");
return
constructorArgs == null ?
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type) as ViewStream :
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type, constructorArgs) as ViewStream;
var type = find(friendlyName);
return Activator.CreateInstance(type, constructorArgs) as ViewStream;
}
/// <summary>