为嘛调不到这个方法?大侠们帮帮忙……
public class MockAnnounceService : IAnnounceService
{
public List<AnnounceInfo> GetAnnounceByCategory(CategoryInfo category)
{
List<AnnounceInfo> announces = new List<AnnounceInfo>();
for (int i = 1; i <= 10; i++)
{
AnnounceInfo announce = new AnnounceInfo
{
ID = i,
Title = category.Name + "的第" + i + "则公告",
Content = "全体同学早上七点起床做俯卧撑!"
};
announces.Add(announce);
}
return announces;
}
这是实现接口的类,
这是接口的定义:
public class ICategoryService
{
/// <returns></returns>
CategoryInfo GetDetail(int id);
/// <summary>
/// 取得所有分类
/// </summary>
/// <returns></returns>
List<CategoryInfo> GetAll();
}
}
这是组件生成类:
public sealed class ServiceBuilder
{
/// <summary>
/// 创建分类服务组件
/// </summary>
/// <returns>分类服务组件</returns>
public static ICategoryService BulidCategoryService()
{
return new MockCategoryService();
}
/// <summary>
/// 创建公告服务组件
/// </summary>
/// <returns>公告服务组件</returns>
public static IAnnounceService BuildAnnounceService()
{
return new MockAnnounceService();
}
}
这是调用的地方:
public ActionResult Index()
{
ICategoryService cServ = ServiceBuilder.BulidCategoryService();
ViewData["Categories"] = cServ.GetAll();
return View("Index");
}
红色为出错处:"MvcWeb.Models.Interfaces.ICategoryService.GetAll()"不可访问,因为它受保护级别限制
------解决方案--------------------public class MockAnnounceService : IAnnounceService
public static ICategoryService BulidCategoryService()
{
return new MockCategoryService();
}
public class ICategoryService {
/// <returns></returns>
CategoryInfo GetDetail(int id);
/// <summary>
/// 取得所有分类
/// </summary>
/// <returns></returns>
List<CategoryInfo> GetAll();
}
}
------解决方案--------------------起码把MockCategoryService这个类发出来看看把。
------解决方案--------------------static下
------解决方案--------------------看你的类名,好像不是继承ICategoryService的。你应该有一个MockCategoryService类。发上来瞧瞧。