相关疑难解决方法(0)

覆盖静态方法

我通过继承RolesService来扩展一个新类.在RolesService中,我有一个静态方法,我想在我新派生的类中覆盖它.当我从派生对象进行调用时,它不使用重写的静态方法,它实际上调用基类方法.有任何想法吗?

public class RolesService : IRolesService
{
    public static bool IsUserInRole(string username, string rolename)
    {
        return Roles.IsUserInRole(username, rolename);
    }
}

public class MockRoleService : RolesService
{
    public new static bool IsUserInRole(string username, string rolename)
    {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc

39
推荐指数
4
解决办法
6万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1