1 2 module witchcraft.impl.fields; 3 4 version(aggressive): 5 6 import witchcraft; 7 8 import std.variant; 9 10 template FieldImpl(alias T, string name) 11 { 12 // TODO : Determine this more reliably. 13 static if(__traits(getProtection, __traits(getMember, T, name)) == "public") 14 { 15 mixin WitchcraftField; 16 17 alias FieldImpl = FieldMixin!(T, name); 18 } 19 else 20 { 21 class FieldImpl : Field 22 { 23 override Variant get(Variant instance) const 24 { 25 assert(0, "Field " ~ name ~ " is inaccessible."); 26 } 27 28 const(Attribute)[] getAttributes() const 29 { 30 assert(0, "Field " ~ name ~ " is inaccessible."); 31 } 32 33 const(Type) getDeclaringType() const 34 { 35 assert(0, "Field " ~ name ~ " is inaccessible."); 36 } 37 38 const(TypeInfo) getDeclaringTypeInfo() const 39 { 40 assert(0, "Field " ~ name ~ " is inaccessible."); 41 } 42 43 string getFullName() const 44 { 45 assert(0, "Field " ~ name ~ " is inaccessible."); 46 } 47 48 @property 49 string getName() const 50 { 51 return name; 52 } 53 54 string getProtection() const 55 { 56 return __traits(getProtection, __traits(getMember, T, name)); 57 } 58 59 override const(Type) getValueType() const 60 { 61 assert(0, "Field " ~ name ~ " is inaccessible."); 62 } 63 64 override const(TypeInfo) getValueTypeInfo() const 65 { 66 assert(0, "Field " ~ name ~ " is inaccessible."); 67 } 68 69 @property 70 override bool isStatic() const 71 { 72 assert(0, "Field " ~ name ~ " is inaccessible."); 73 } 74 75 @property 76 bool isAccessible() const 77 { 78 return __traits(hasMember, typeof(this), "member"); 79 } 80 81 @property 82 override bool isWritable() const 83 { 84 return __traits(compiles, { 85 T instance = void; 86 typeof(member) value = void; 87 88 __traits(getMember, instance, name) = value; 89 }); 90 } 91 92 override void set(Variant instance, Variant value) const 93 { 94 assert(0, "Field " ~ name ~ " is inaccessible."); 95 } 96 } 97 } 98 }