Tag: 接口 实现

在MVC4中显示和错误,我必须实现一些接口,但我已经完成了它

我正在尝试创建自己的filter属性,以支持多语言。 这个想法很简单。 URL代表语言。 * http://host.ext/en/ rest_of_the_url *将以英文和 * http://host.ext/ hy / rest_of_the_url *将以亚美尼亚语开放。 问题是在运行时它会说MultilingualActionFilterAttribute 以下是错误文本“给定的filter实例必须实现以下一个或多个filter接口:IAuthorizationFilter,IActionFilter,IResultFilter,IExceptionFilter”。 在这里,我将它用作全局filter。 namespace TIKSN.STOZE.WebApp { public class FilterConfig { public static void RegisterGlobalFilters(System.Web.Mvc.GlobalFilterCollection filters) { filters.Add(new TIKSN.STOZE.Common.MultilingualActionFilterAttribute()); filters.Add(new System.Web.Mvc.HandleErrorAttribute()); } } } 我在这里定义它。 namespace TIKSN.STOZE.Common { public class MultilingualActionFilterAttribute : System.Web.Mvc.ActionFilterAttribute { public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext) { string language = […]

在C#中,是否可以使用具有不同名称的成员实现接口成员,就像在VB.NET中一样?

好吧,这是一个我要问的问题,而不是在展示良好的编码实践(这实际上可能被认为是一种不好的做法),而是在“可以”的问题上完成。 也就是说,在VB.NET中你实现了这样的接口…… Sub SomeInterfaceMember() Implements ISomeInterface.SomeInterfaceMember End Sub 而在C#中你明确地这样做(只能通过界面调用)…… void ISomeInterface.SomeInterfaceMember(){} 或者更简单地,隐式地像这样(在这种情况下你可以直接调用它,或通过接口)…… void SomeInterfaceMember(){} // <– This name matches the interface member 但是,关于VB,您也可以使用您想要的任何名称来执行此操作… Sub SomeRandomMemberName() // <– This name doesn't match the interface member Implements ISomeInterface.SomeInterfaceMember End Sub 换句话说,处理实现的方法可以具有与接口的成员名称完全不同的名称。 我只是想知道在C#中是否有类似的东西。 (是的,我知道我可以简单地做一个显式接口,然后通过另一个’wrapper’成员使用一个简单的委托给它的不同名称来访问它,但是在VB.NET中,你只需要一个方法。) 那可以吗? 标记