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

拡張メソッドが認識されません。何が問題なのですか?

4

1 に答える 1

7

呼び出しの前にthis:

public class StoreController : Controller
{
    //
    // GET: /Store/

    public string Index()
    {
        return this.GetMemberName();
    }
}
于 2012-10-17T06:19:31.290 に答える