How can I declare my Basepage class in an asp.net webforms project to also implement IBasePage?
public abstract class BasePage<T> : Page where T : class
{
}
and the interface
public interface IBasePage
{
UserProfile UserProfile { get;}
bool IsStreamingAdmin {get;}
int? EmplId {get;}
}
my ultimate goal is to be able to write code this like:
IBasePage page = HttpContext.Current.Handler as IBasePage;
if (page.IsStreamingAdmin)
{
//do something here....
}
你的问题对我来说并不完全清楚,但你不能这样做:
public abstract class BasePage<T> : Page, IBasePage where T : class { }
public abstract class BasePage<T> : Page, IBasePage where T : class { }
If your class implements all the methods defined in the interface
your code is able to compile and you will be able to call an instance
of your abstract class.
Calling page.IsStreamingAdmin
will result in returning the value of the class you have an instance of.
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.