getSymbolsByUDA in constructor/member functions

frame frame86 at live.com
Thu Jun 16 07:34:37 UTC 2022


On Wednesday, 15 June 2022 at 12:26:40 UTC, cc wrote:

> Why doesn't this work?  There is nothing in the foreach body.
>
> ```d
> alias ALL = getSymbolsByUDA!(Def, XML);
> pragma(msg, ALL.stringof);
> ```
> reports `tuple(this.x, this.y)`.  Why is `this.` added?

I can only answer this partially, I guess `this` is just added 
because `getSymbolsByUDA` want an instance but `@XML` is only 
seen as a type. As instance, you need to write `@XML()` instead:

```d
class XML {
     static opCall() {
         return new XML();
     }
}

class Def {
	@XML() {
		int x;
		int y;
	}
	int z;

	this() {
		static foreach (sym; getSymbolsByUDA!(Def, XML)) {
		}
	}
}
```


More information about the Digitalmars-d-learn mailing list