@@ -46,6 +46,8 @@ public abstract partial class ExchangeAPI : BaseAPI, IExchangeAPI
46
46
private static readonly Dictionary < string , IExchangeAPI ? > apis = new Dictionary < string , IExchangeAPI ? > ( StringComparer . OrdinalIgnoreCase ) ;
47
47
private bool disposed ;
48
48
49
+ private static readonly Dictionary < string , string > classNamesToApiName = new Dictionary < string , string > ( ) ;
50
+
49
51
#endregion Private methods
50
52
51
53
#region API Implementation
@@ -230,7 +232,8 @@ static ExchangeAPI()
230
232
{
231
233
api . Dispose ( ) ;
232
234
apis [ api . Name ] = null ;
233
- }
235
+ classNamesToApiName [ type . Name ] = api . Name ;
236
+ }
234
237
235
238
// in case derived class is accessed first, check for existance of key
236
239
if ( ! ExchangeGlobalCurrencyReplacements . ContainsKey ( type ) )
@@ -291,12 +294,20 @@ public void Dispose()
291
294
}
292
295
}
293
296
294
- /// <summary>
295
- /// Get an exchange API given an exchange name (see ExchangeName class)
296
- /// </summary>
297
- /// <param name="exchangeName">Exchange name</param>
298
- /// <returns>Exchange API or null if not found</returns>
299
- public static IExchangeAPI ? GetExchangeAPI ( string exchangeName )
297
+ public static IExchangeAPI ? GetExchangeAPIFromClassName ( string className )
298
+ {
299
+ if ( ! classNamesToApiName . TryGetValue ( className , out string exchangeName ) )
300
+ throw new ArgumentException ( "No API available with class name " + className ) ;
301
+
302
+ return GetExchangeAPI ( exchangeName ) ;
303
+ }
304
+
305
+ /// <summary>
306
+ /// Get an exchange API given an exchange name (see ExchangeName class)
307
+ /// </summary>
308
+ /// <param name="exchangeName">Exchange name</param>
309
+ /// <returns>Exchange API or null if not found</returns>
310
+ public static IExchangeAPI ? GetExchangeAPI ( string exchangeName )
300
311
{
301
312
// note: this method will be slightly slow (milliseconds) the first time it is called and misses the cache
302
313
// subsequent calls with cache hits will be nanoseconds
0 commit comments