core.reflect vs c++ reflection

WebFreak001 d.forum at webfreak.org
Tue Sep 28 07:10:43 UTC 2021


On Monday, 27 September 2021 at 15:17:39 UTC, Stefan Koch wrote:
> On Monday, 27 September 2021 at 13:12:32 UTC, WebFreak001 wrote:
>
>> If it's mistyped, the compiler will complain that it doesn't 
>> exist
>>
> core.reflect will tell you that you tried to resolve a name 
> which does not exist as well.
>
>> When it's an identifier, IDE refactorings (automated renaming) 
>> will find it, while it wouldn't find it in a string, 
>> especially the more generic the name is (which is common for 
>> template types `T`)
>>
>> C# has `nameof(T)` which just returns `"T"` or for 
>> `nameof(Foo.T)` it also just returns `"T"`
>
> That's valid.
> I have to think about what to do about that.
> Maybe remove the "" for the refactoring?
> a simple search for `nodeFromName\(\"$ID\"\)` maybe?
> It's the only primitive in code reflect which does this.

maybe for `nodeFromName("T")` leave it unsolved but there could 
also be a `nodeFrom!T` which could additionally check for the 
type of T and return the correct node type (like EnumDeclaration 
from enums)

This would additionally remove the need to do casts (and 
potentially mess up)


More information about the Digitalmars-d mailing list