www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I get class member type?

reply Marc <jckj33 gmail.com> writes:
I didn't find how using traits I could get a class member type? I 
need to test if give class member is not immutable, I find 
isMutable but not how get a type from give class member to pass 
to it.
Jan 14 2018
parent reply Marc <jckj33 gmail.com> writes:
On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote:
 I didn't find how using traits I could get a class member type? 
 I need to test if give class member is not immutable, I find 
 isMutable but not how get a type from give class member to pass 
 to it.
for clarify, I want all this at compile time, imaginary code example:
 static foreach(field; FieldNameTuple!C) {
 		static if(isFunction!(__traits(getMember, C, field)) &&  
 isMutable(typeof(__traits(getMember, C, field)))) {
			// do something
		}
	}
Jan 14 2018
parent Marc <jckj33 gmail.com> writes:
On Sunday, 14 January 2018 at 19:08:44 UTC, Marc wrote:
 On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote:
 I didn't find how using traits I could get a class member 
 type? I need to test if give class member is not immutable, I 
 find isMutable but not how get a type from give class member 
 to pass to it.
for clarify, I want all this at compile time, imaginary code example:
 static foreach(field; FieldNameTuple!C) {
 		static if(isFunction!(__traits(getMember, C, field)) &&  
 isMutable(typeof(__traits(getMember, C, field)))) {
			// do something
		}
	}
I solved with this: enum isMutableString(string field) = is(typeof(__traits(getMember, Field, field)) == string);
Jan 14 2018