using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcMusicStore.Controllers
{
public class StoreController : Controller
{
//
// GET: /Store/
public string Index()
{
return "MvcMusicsStore.Controllers.StoreController.Index";
}
}
}
How to return a method's fully-qualified name on the fly?
Without any hard coding? Something like maybe?
public string Index()
{
return GetType().FullName + GetMemberName();
}
static string GetMemberName([CallerMemberName] string memberName = "")
{
return memberName;
}
Or perhaps prettier:
public string Index()
{
return GetMemberName(this);
}
static string GetMemberName(
object caller, [CallerMemberName] string memberName = "")
{
return caller.GetType().FullName + "." + memberName;
}
(I used static
because I assume in the real code you'd want to put the method in a utility class somewhere)
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