Question

Is it possible using D's builtin traits and/or std.traits to detect whether a function (either within a class/struct or without) is annotated with @property? I know @property isn't really an attribute, but I thought __traits(getAttributes, ...) might do it (no such luck).

Was it helpful?

Solution

In general, I would think that it would be better to just test that the expression you want to use compiles (e.g. is(typeof(var.prop))), but if for some reason you really need to know that a function is marked with @property, then you can use std.traits.functionAttributes to get that information. Something like

enum isProperty = (functionAttributes!(MyType.prop) & FunctionAttribute.property) != 0;

should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top