Is there an efficient way to get the control name "HelloWorld"
when all I know is the class HelloWorldController
?
Maybe something like:
var str = HelloWorldController.NetExtensionMethodWhichRetursActionName(); // str = "HelloWorld"
Edit: can't exist as (currently) extension method only exist for instances
or
var str = NetUtilClass.MethodWhichRetursActionNameFromControllerclass(typeof(HelloWorldController)); // str = "HelloWorld"
or something else...
I know I could write something like:
string GetName<T>() where T : Controller { var s = typeof(T).Name; return s.Delete(s.Length - "Controller".Length; }
but I guess this functionality is already available in the framework.
DefaultHttpControllerSelector
has a protected method to get the controller's name base on the default <controller name>Controller
class naming convention.
Going as far as inheriting DefaultHttpControllerSelector
in a utility class could do the trick. I don't need this anymore so I'm leaving the implementation to your imagination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With