using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Web.Mvc;
namespace MvcMusicStore.Controllers
{
public class StoreController : Controller
{
//
// GET: /Store/
public string Index()
{
// ERROR call extension method here
return GetMemberName();
}
}
public static class Utilities
{
public static string GetMemberName(this Controller caller, [CallerMemberName] string memberName = "")
{
return caller.GetType().FullName + "." + memberName;
}
}
}
我的扩展方法无法识别,出了什么问题?
答案 0 :(得分:7)
使用this
:
public class StoreController : Controller
{
//
// GET: /Store/
public string Index()
{
return this.GetMemberName();
}
}