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 myPage = HttpContext.Current.Handler as Page;
But I can't call my function ReadPermission because it's not recognizing it:
myPage.readPermissions();
How do I call my implemented function?
You need to cast myPage
to 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()
{
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.