1 2 module witchcraft.fields; 3 4 import witchcraft; 5 6 import std.algorithm; 7 import std.array; 8 import std.variant; 9 10 /++ 11 + Represents and grants access to a single field defined on a type. 12 ++/ 13 abstract class Field : Member 14 { 15 abstract Variant get(Variant instance) const; 16 17 T get(T = Variant, O)(O instance) const 18 { 19 auto result = this.get(Variant(instance)); 20 21 static if(is(T == Variant)) 22 { 23 return result; 24 } 25 else 26 { 27 return result.get!T; 28 } 29 } 30 31 @property 32 abstract const(Type) getValueType() const; 33 34 @property 35 abstract const(TypeInfo) getValueTypeInfo() const; 36 37 /++ 38 + Checks if the field is declared as static. This returns true if the 39 + is directly accessible on the type that is declared on (rather that on 40 + an instance of that type). 41 + 42 + Returns: 43 + `true` if this field is static. 44 ++/ 45 @property 46 abstract bool isStatic() const; 47 48 /++ 49 + Checks if the field can be written to. 50 + 51 + Returns: 52 + `true` if the value of the field can be set. 53 ++/ 54 @property 55 abstract bool isWritable() const; 56 57 abstract void set(Variant instance, Variant value) const; 58 59 void set(T, O)(O instance, T value) const 60 { 61 this.set(Variant(instance), Variant(value)); 62 } 63 64 override string toString() const 65 { 66 return getValueTypeInfo.toString ~ " " ~ getName; 67 } 68 }