[英]How do I call an implemented interface function
I have a "Page" that implement my own "Permission" interface. 我有一个实现我自己的“权限”界面的“页面”。
public interface PagePermissions{
Dictionary<string, Permission> readPermissions();
}
public partial class myWebPage: System.Web.UI.Page, PagePermissions
{
protected void Page_Load(object sender, EventArgs e)
{
}
Dictionary<string, Permission> PagePermissions.readPermissions()
{
Dictionary<string, Permission> results = new Dictionary<string, Permission>();
return results;
}
}
In my master page, I get a reference to the current Page object. 在我的母版页中,获得对当前Page对象的引用。
Page myPage = HttpContext.Current.Handler as Page;
But I can't call my function ReadPermission because it's not recognizing it: 但是我无法调用我的函数ReadPermission,因为它无法识别它:
myPage.readPermissions();
How do I call my implemented function? 如何调用我的已实现函数?
You need to cast myPage
to PagePermissions
. 您需要将
myPage
PagePermissions
为PagePermissions
。
PagePermissions myPage = HttpContext.Current.Handler as PagePermissions;
myPage.readPermissions();
尝试将myPage
投射到您的界面。
PagePermissions myPagePermissions = (PagePermissions)myPage;
Why are you using explicit implementation of the interface function? 为什么要使用接口函数的显式实现? Think about changing the code line
考虑更改代码行
Dictionary<string, Permission> PagePermissions.readPermissions()
{
to 至
public Dictionary<string, Permission> readPermissions()
{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.