interpolateMixin

Takes code in the form of a string and interpolates variables defined in the form of ${variableName}. Usefull in combination with the q{} string literal, to keep syntax highlighting for mixed in code and avoid string concatenations, which keeps the code readable

@safe pure nothrow static
string
interpolateMixin
(
string code
)

Parameters

code string

code to be mixed in

Examples

class Foo {
    int id = 1;
    uint age = 23;
    string name = "foo";
}

auto foo = new Foo;

static foreach (member; FieldNameTuple!(Foo)) {
    mixin(interpolateMixin(q{
        writeln("Field ${member} has a value of: ", foo.${member});
    }));
}

Meta