0

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?

3 Answers 3

6

You need to cast myPage to PagePermissions.

PagePermissions myPage = HttpContext.Current.Handler as PagePermissions;
myPage.readPermissions();
0
1

Try casting myPage to your interface.

PagePermissions myPagePermissions = (PagePermissions)myPage;
0

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()
{
2
  • It will still need to be cast to his interface, PagePermissions to access the members--so there's no real difference.
    – STW
    May 30, 2012 at 19:30
  • Wrong. Implicitly implemented interface methods are part of the class's public interface. No need to cast in order to call the function then.
    – Wormbo
    May 30, 2012 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.