Open AdamSpeight2008 opened 7 years ago
Unless Me.Foo()
is valid, NameOf(Me)
would be inconsistent.
There is (or was) a more general request that would cover the current method/property. Solving it for just the class/module is just too limiting.
Why is repeating the type name an issue here?
I have a couple of questions.
What happens, if NameOf(Me) is used in a Method in Foo, and called somewhere from Bar, and that Method gets inlined? Reflection would return something different than NameOf, right? I would not like that.
And would you expect that NameOf(Me) is returning different results in derived classes? So, if you have
Class Foo Function FooMethod as String Return NameOf(Me) End Fuction End Class
Class Bar Inherits Foo End Class
What happens if you call Foo.FooMethod in contrast to Bar.FooMethod? Remember: the Return-Value is prepared already at Compile-Time!
@AnthonyDGreen: I read "Doesn't require repetition of the TypeName" to mean "doesn't require magic strings".
@jrmoreno1 you don't need magic strings, you can just say NameOf(TypeName)
@AnthonyDGreen : yep, you're right. Can't remember what I was thinking, but what I said is obviously wrong.
Ported from Roslyn Repo
NameOf(Me)
should evaluate to the Class / Structure / Module name, it is used in.Advantage Doesn't require reflection. Doesn't require repetition of the TypeName