1 module selectors.has; 2 3 import std.algorithm; 4 import std.array; 5 import std.traits; 6 7 8 import introspection.callable; 9 import introspection.attribute; 10 import introspection.parameter; 11 12 version(unittest) { 13 import fluent.asserts; 14 } 15 16 /// Callables checks 17 struct HasCallable { 18 private { 19 Callable callable; 20 } 21 22 this(Callable callable) @safe pure nothrow { 23 this.callable = callable; 24 } 25 26 bool anyParameterOfType(string typeName) @safe pure nothrow { 27 foreach (Parameter parameter; callable.parameters) { 28 if(parameter.type.name == typeName || parameter.type.fullyQualifiedName == typeName) { 29 return true; 30 } 31 } 32 33 return false; 34 } 35 } 36 37 /// Callables checks 38 HasCallable has(Callable callable) @safe pure nothrow { 39 return HasCallable(callable); 40 } 41 42 43 /// Checks if it has an attribute of type 44 unittest { 45 @("test") 46 void test(string, int) { } 47 48 enum item = describeCallable!test; 49 50 item.has.anyParameterOfType("other").should.equal(false); 51 item.has.anyParameterOfType("string").should.equal(true); 52 item.has.anyParameterOfType("int").should.equal(true); 53 } 54 55