diff --git a/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs b/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs index 5c3f0e389..3b8423c6e 100644 --- a/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs +++ b/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs @@ -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 myAssemblyNames = new(); + readonly Dictionary myTypeLookupTable = new(); private PrimitiveManager() { myLoadAllTypes(); @@ -100,15 +101,14 @@ namespace BCG { } /// - /// Returns the Type name corresponding to the primitive name + /// Returns the Type corresponding to the primitive name /// /// /// - 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)); /// /// Constructs and returns a ViewStream of type corresponding to the friendly name @@ -123,12 +123,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; } /// diff --git a/src/DataStreamSuite/DataStreamExpressions/PrimitiveExpression.cs b/src/DataStreamSuite/DataStreamExpressions/PrimitiveExpression.cs index 1b90cd17e..1c87372e6 100644 --- a/src/DataStreamSuite/DataStreamExpressions/PrimitiveExpression.cs +++ b/src/DataStreamSuite/DataStreamExpressions/PrimitiveExpression.cs @@ -20,7 +20,7 @@ public class PrimitiveExpression : StatementExpression { } public override string print(int startCol, IList activeBindings) { - string prelude = "new " + PrimitiveManager.instance.find(myName) + " ("; + string prelude = "new " + PrimitiveManager.instance.find(myName).Name + " ("; return prelude + myPrintArgs(startCol + prelude.Length, activeBindings) + ")"; }