扩展方法无法识别,有什么不对?

时间:2012-10-17 06:18:44

标签: c#

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;
        }
    }
}

我的扩展方法无法识别,出了什么问题?

1 个答案:

答案 0 :(得分:7)

使用this

加注通话
public class StoreController : Controller
{
    //
    // GET: /Store/

    public string Index()
    {
        return this.GetMemberName();
    }
}