J
jeff m
Hi there - I'm trying to figure out how to model a fluent interface for
asp.net page navigation and am getting stuck - wondering if anyone has ideas
on how to accomplish something like the following:
public class Page1 : BasePage
{
public class InputParameters : PageInputParameters<Page1>
{
public DateTime StartDate;
public InputParameters( DateTime startDate ) { this.StartDate =
startDate; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
// TODO: determine how to build/model this...
NavController.NavigateToPage<Page2>().WithParams( 1 );
}
}
public class Page2 : BasePage
{
public class InputParameters : PageInputParameters<Page2>
{
public int ReportId;
public InputParameters( int reportId ) { this.ReportId = reportId; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
// TODO: determine how to build/model this...
NavController.NavigateToPage<Page3>().WithParams( "test name" );
}
}
public class Page3 : BasePage
{
public class InputParameters : PageInputParameters<Page3>
{
public string Name;
public InputParameters( string name ) { this.Name = name; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
NavController.NavigateToPage<Page3>().WithParams( DateTime.Today );
}
}
public abstract class PageInputParameters<AssociatedPageType> where
AssociatedPageType : BasePage
{
public BasePage ParentPage { get { return default(AssociatedPageType); } }
public void NavigateToPage() { HttpContext.Current.Response.Redirect(
this.BuildNavigateUrl() ); }
public virtual string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl; }
}
public abstract class BasePage : System.Web.UI.Page
{
public abstract string AppRelativeUrl { get; }
}
It doesn't seem possible, given my approach, since NavigateToPage<T>() would
need to return a dynamic interface that declares WithParams() - but the input
parameters to that method would need to be dynamic - not sure how to
accomplish that (if it could be accomplished at all).
Thanks for any ideas/help anyone can give!
asp.net page navigation and am getting stuck - wondering if anyone has ideas
on how to accomplish something like the following:
public class Page1 : BasePage
{
public class InputParameters : PageInputParameters<Page1>
{
public DateTime StartDate;
public InputParameters( DateTime startDate ) { this.StartDate =
startDate; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
// TODO: determine how to build/model this...
NavController.NavigateToPage<Page2>().WithParams( 1 );
}
}
public class Page2 : BasePage
{
public class InputParameters : PageInputParameters<Page2>
{
public int ReportId;
public InputParameters( int reportId ) { this.ReportId = reportId; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
// TODO: determine how to build/model this...
NavController.NavigateToPage<Page3>().WithParams( "test name" );
}
}
public class Page3 : BasePage
{
public class InputParameters : PageInputParameters<Page3>
{
public string Name;
public InputParameters( string name ) { this.Name = name; }
public override string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl + "?rid=" + this.ReportId; }
}
public void RedirectUser()
{
NavController.NavigateToPage<Page3>().WithParams( DateTime.Today );
}
}
public abstract class PageInputParameters<AssociatedPageType> where
AssociatedPageType : BasePage
{
public BasePage ParentPage { get { return default(AssociatedPageType); } }
public void NavigateToPage() { HttpContext.Current.Response.Redirect(
this.BuildNavigateUrl() ); }
public virtual string BuildNavigateUrl() { return
ParentPage.AppRelativeUrl; }
}
public abstract class BasePage : System.Web.UI.Page
{
public abstract string AppRelativeUrl { get; }
}
It doesn't seem possible, given my approach, since NavigateToPage<T>() would
need to return a dynamic interface that declares WithParams() - but the input
parameters to that method would need to be dynamic - not sure how to
accomplish that (if it could be accomplished at all).
Thanks for any ideas/help anyone can give!