factory

Create instance of class specified by the module symbol and a string representing the name of the class. The class must either have no constructors or have a default constructor.

factory
(
alias mod
)
(
string classname
)

Parameters

mod

symbol representing the module that the class is in

classname string

string representing the name of the class

Return Value

Type: Object

null if failed

Examples

module foo.bar;

class C
{
    this() { x = 10; }
    int x;
}

void main()
{
    auto c = cast(C)factory!(foo.bar)("C");
    assert(c !is null && c.x == 10);
}

Meta