Created
March 26, 2022 16:35
-
-
Save Char0394/a8e08e96977f4a2fda784b3ea204f612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuickTourBuilder<T> | |
where T : BaseQuickTourPage, IQuickTourLauncher, new() | |
{ | |
public static QuickTourBuilder<T> Initialize() | |
=> new QuickTourBuilder<T>(new T()); | |
public QuickTourBuilder<T> Next(BaseQuickTourPage page) | |
{ | |
_pages.Last().NextPage = page; | |
AddPage(page); | |
return this; | |
} | |
public IQuickTourLauncher Build() | |
=> _pages.Select(page => | |
{ | |
page.TotalSteps = _pages.Count; | |
return page; | |
}) | |
.ToList() | |
.OfType<IQuickTourLauncher>() | |
.First(); | |
private QuickTourBuilder(T initialPage) => AddPage(initialPage); | |
private void AddPage(BaseQuickTourPage page) | |
{ | |
_pages ??= new List<BaseQuickTourPage>(); | |
_pages.Add(page); | |
page.ActualStep = _pages.Count; | |
} | |
private IList<BaseQuickTourPage> _pages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment