You could probably throw in a traits(compiles) right above.
foreach(...) { // or maybe compiles, getProtection(getMember)) static if(__traits(compiles, __traits(getMember,Foo.init, mem)) { enum prot = __traits(getProtection, __traits(getMember, Foo.init, mem)); // and so on } }I haven't actually tried this but generally static if(compiles) is a way to work around unwanted error messages.