A generic way to instantiate QLNet derived classes

In this article we present how you can:

  • Make a Calendar QLNet class instantiation based on its name. Ex,  i want to instantiate a UnitedStates QLNet Calendar from the string “UnitedStates” (I would obtain such string from an Excel exposed function, for example).
  • Retrieve from the QLNet assembly every type derived from the Calendar class ( a use case would be to get this list of calendar names  and expose it to a QLNet consumer application).

The sample console project contains a reference to QLNet.dll (you can obtain it from nuget package manager).

QLNet console project

QLNet console project

 

 

 

 

 

 

QLNet class instantiation

The following code makes it possible to load the QLNet assembly, and create an instance (in the ‘cldr’ variable) of a Calendar derived class identified by its name (“UnitedStates”).

This is quite convenient if you want to avoid a repetition of if/switch, and find a generic way to instantiate those classes from a string.

Get QLNet derived classes names

This second code allows to obtain the full list of calendar names:

Here is the final output (which can then be exposed to users of a QLNet based application for parameters selection):

QLNet class instantiation

QLNet Calendars

 

 

Facebooktwittergoogle_plusredditlinkedinmail