Dynamically Creating Class (Reflection in C#)
I need to dynamically create a class based on a parameter passed into a class method. Basically the method takes in a string that contains the name of the class I need to create a new instance of.
I need something along these lines.
ClassMethod someMethod(className As %String)
{
set classObject = ##class(className).%New()
...
}
Trying to do this right results in a class not found error because it seems to be treating the variable as a literal string.
You can do this with the $CLASSMETHOD function in ObjectScript:
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
ClassMethod someMethod(className As %String) { set classObject = $CLASSMETHOD(className,"%New") ... }
Take my up vote you evil genius! Thank you!
There is also a good article by @Olga Phomina on Reflection in ObjectScript.