每次我需要传递一个新的页面类时我调用的类我必须构建一个新的构造函数,我知道泛型会解决这个问题。有人可以告诉我如何做到这一点吗?
public class CheckUserAuthentication
{
private Page1 _p1;
private Page2 _p2;
public CheckUserAuthentication(Page1 p1)
{
_p1 = p1;
}
public CheckUserAuthentication(Page2 p2)
{
_p2 = p2;
}
public void AuthenticateUser(out Person person, out Animal animal)
{
If(_p1 != null)
{
_p1.Response.Write("writes to P1 page");
}
else
{
_p2.Response.Write("writes to P2 page");
}
}
}
我的第 1 页的呼叫代码
public Page1()
{
_checkUserAuthentication = new CheckUserAuthentication(this);
}
public CheckUserAuthentication CheckUserAuthentication
{
get { return _checkUserAuthentication; }
}
CheckUserAuthentication.AuthenticateUser(out person, out animal);