Get Page.Master Instance without Cast
I am trying to get a master's page instance without cast开发者_如何学运维.
Something like this but without cast
var masterPage = (MasterPageName)Page.Master;
if (masterPage != null) {
masterPage.Foo = false;
}
Is there any workaround for this?
thanks
I would make MasterPageName to implement an interface IFoo which has the boolean Foo defined, so in your code above you could check if Page.Master is IFoo and you do not need any cast.
精彩评论