digitalmars.D - missing: __traits(isPublic (private, etc...)
- Lloyd Dupont (26/26) Jun 20 2011 I am working a reflection / introspection library (dynamic / at runtime,...
- Adam Ruppe (13/13) Jun 20 2011 Indeed, this would be nice. I want it for my web.d thing.
- Lloyd Dupont (18/18) Jun 20 2011 Hey Adam! Thanks again for your web.d!
I am working a reflection / introspection library (dynamic / at runtime, as opposed to compile time with template and mixin). Now I can create "PropertyInfo" classes for property with very little code and it all works well. I'm hitting a problem, trying to "register" all property of my class automatically. I have a vanilla implementation like that: ===== void RegisterProperties(T)() { foreach(mn ; __traits(derivedMembers, T)) GetProperty!(T, mn); } ===== The problem is, it's trying to register private properties! (and of course fail, due to access rights...) So far I have test like === static if(mixin("__traits(compiles, t." ~memberName ~")") ) { getter = &GETTER!(T, memberName); } ==== which test that the thing is a property. But how could I test it's a ***public*** property? if not possible, wouldn't it be a nice trait addition?
Jun 20 2011
Indeed, this would be nice. I want it for my web.d thing. But, as far as I know, there's no way to get it at all right now. A while ago, I tried to add it to the compiler. The problem is protection is stored with the symbol itself, not the thingy returned by getMember - that's always considered public by the compiler. So if you pass the actual Class.member, it's easy to see if it's public or not, but the getMember doesn't say. (Which is why it compiles in the first place... otherwise the private members would give visibility errors when you tried to use it there.) In the compiler, if there was an informational field for protection added, the trait could be made to work, but I haven't gotten around to trying to patch that yet and afaik no one else is interested enough to look either.
Jun 20 2011
Hey Adam! Thanks again for your web.d! My introspection class went along quite well, thanks in no small part to you! ;) implementing INotifyPropertyChanged now and .. data binding next! :) "Adam Ruppe" wrote in message news:itnfqc$kg2$1 digitalmars.com... Indeed, this would be nice. I want it for my web.d thing. But, as far as I know, there's no way to get it at all right now. A while ago, I tried to add it to the compiler. The problem is protection is stored with the symbol itself, not the thingy returned by getMember - that's always considered public by the compiler. So if you pass the actual Class.member, it's easy to see if it's public or not, but the getMember doesn't say. (Which is why it compiles in the first place... otherwise the private members would give visibility errors when you tried to use it there.) In the compiler, if there was an informational field for protection added, the trait could be made to work, but I haven't gotten around to trying to patch that yet and afaik no one else is interested enough to look either.
Jun 20 2011