Using "nameof" for invoking a method

My IDE Rider suggested that I should use the nameof function as an alternative to typing the function’s name string myself.

So instead of:

Invoke("ReloadLevel"), 1f);

It is:

Invoke(nameof(ReloadLevel), 1f);

Now you’re directly referencing the method instead of just typing a string.

Now if you use “Rename Symbol”, it will update the method name within the Invoke function too. And if you misspell the method name within the Invoke function, it’ll immediately give you an error.

This seemed like really great advice from Rider so I thought I’d share it on here.

11 Likes

This sounds incredibly handy, thanks for sharing!

Yea that’s what I miss from Rider, I would still be using it but it’s so slow.

Rider is so much faster than VS lol, are you high ?

Seriously? Rider takes ages to launch. It sometimes even takes seconds to highlight stuff!

Privacy & Terms