Fix check on whether a member was a function

Checks on some kinds of members, such as constants, would trip up with the isCallable trait.
This commit is contained in:
Mike Bierlee 2016-12-26 16:16:18 +01:00
parent 10d24eb9fb
commit 925c3f4119
2 changed files with 4 additions and 2 deletions

View file

@ -264,9 +264,10 @@ class AutowiredRegistration(RegistrationType : Object) : Registration {
private void delegate() getPreDestructor(RegistrationType instance) { private void delegate() getPreDestructor(RegistrationType instance) {
void delegate() preDestructor = null; void delegate() preDestructor = null;
foreach (memberName; __traits(allMembers, RegistrationType)) { foreach (memberName; __traits(allMembers, RegistrationType)) {
mixin(`import ` ~ moduleName!RegistrationType ~ `;`);
static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName))) static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName)))
&& __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && __traits(getProtection, __traits(getMember, instance, memberName)) == "public"
&& isCallable!(__traits(getMember, instance, memberName)) && isFunction!(mixin(fullyQualifiedName!RegistrationType ~ `.` ~ memberName))
&& hasUDA!(__traits(getMember, instance, memberName), PreDestroy)) { && hasUDA!(__traits(getMember, instance, memberName), PreDestroy)) {
preDestructor = &__traits(getMember, instance, memberName); preDestructor = &__traits(getMember, instance, memberName);
} }

View file

@ -390,9 +390,10 @@ synchronized class DependencyContainer {
private void callPostConstructors(Type)(Type instance) { private void callPostConstructors(Type)(Type instance) {
foreach (memberName; __traits(allMembers, Type)) { foreach (memberName; __traits(allMembers, Type)) {
mixin(`import ` ~ moduleName!Type ~ `;`);
static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName))) static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName)))
&& __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && __traits(getProtection, __traits(getMember, instance, memberName)) == "public"
&& isCallable!(__traits(getMember, instance, memberName)) && isFunction!(mixin(fullyQualifiedName!Type ~ `.` ~ memberName))
&& hasUDA!(__traits(getMember, instance, memberName), PostConstruct)) { && hasUDA!(__traits(getMember, instance, memberName), PostConstruct)) {
__traits(getMember, instance, memberName)(); __traits(getMember, instance, memberName)();
} }