@@ -30,14 +30,7 @@ public class BrowsingContextModule(Broker broker) : Module(broker)
3030{
3131 public async Task < BrowsingContext > CreateAsync ( ContextType type , CreateOptions ? options = null )
3232 {
33- var @params = new CreateCommandParameters ( type ) ;
34-
35- if ( options is not null )
36- {
37- @params . ReferenceContext = options . ReferenceContext ;
38- @params . Background = options . Background ;
39- @params . UserContext = options . UserContext ;
40- }
33+ var @params = new CreateCommandParameters ( type , options ? . ReferenceContext , options ? . Background , options ? . UserContext ) ;
4134
4235 var createResult = await Broker . ExecuteCommandAsync < CreateCommand , CreateResult > ( new CreateCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
4336
@@ -46,12 +39,7 @@ public async Task<BrowsingContext> CreateAsync(ContextType type, CreateOptions?
4639
4740 public async Task < NavigateResult > NavigateAsync ( BrowsingContext context , string url , NavigateOptions ? options = null )
4841 {
49- var @params = new NavigateCommandParameters ( context , url ) ;
50-
51- if ( options is not null )
52- {
53- @params . Wait = options . Wait ;
54- }
42+ var @params = new NavigateCommandParameters ( context , url , options ? . Wait ) ;
5543
5644 return await Broker . ExecuteCommandAsync < NavigateCommand , NavigateResult > ( new NavigateCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
5745 }
@@ -65,35 +53,21 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option
6553
6654 public async Task < LocateNodesResult > LocateNodesAsync ( BrowsingContext context , Locator locator , LocateNodesOptions ? options = null )
6755 {
68- var @params = new LocateNodesCommandParameters ( context , locator ) ;
69-
70- if ( options is not null )
71- {
72- @params . MaxNodeCount = options . MaxNodeCount ;
73- @params . SerializationOptions = options . SerializationOptions ;
74- @params . StartNodes = options . StartNodes ;
75- }
56+ var @params = new LocateNodesCommandParameters ( context , locator , options ? . MaxNodeCount , options ? . SerializationOptions , options ? . StartNodes ) ;
7657
7758 return await Broker . ExecuteCommandAsync < LocateNodesCommand , LocateNodesResult > ( new LocateNodesCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
7859 }
7960
8061 public async Task < CaptureScreenshotResult > CaptureScreenshotAsync ( BrowsingContext context , CaptureScreenshotOptions ? options = null )
8162 {
82- var @params = new CaptureScreenshotCommandParameters ( context ) ;
83-
84- if ( options is not null )
85- {
86- @params . Origin = options . Origin ;
87- @params . Format = options . Format ;
88- @params . Clip = options . Clip ;
89- }
63+ var @params = new CaptureScreenshotCommandParameters ( context , options ? . Origin , options ? . Format , options ? . Clip ) ;
9064
9165 return await Broker . ExecuteCommandAsync < CaptureScreenshotCommand , CaptureScreenshotResult > ( new CaptureScreenshotCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
9266 }
9367
9468 public async Task CloseAsync ( BrowsingContext context , CloseOptions ? options = null )
9569 {
96- var @params = new CloseCommandParameters ( context ) ;
70+ var @params = new CloseCommandParameters ( context , options ? . PromptUnload ) ;
9771
9872 await Broker . ExecuteCommandAsync ( new CloseCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
9973 }
@@ -107,39 +81,21 @@ public async Task<TraverseHistoryResult> TraverseHistoryAsync(BrowsingContext co
10781
10882 public async Task < NavigateResult > ReloadAsync ( BrowsingContext context , ReloadOptions ? options = null )
10983 {
110- var @params = new ReloadCommandParameters ( context ) ;
111-
112- if ( options is not null )
113- {
114- @params . IgnoreCache = options . IgnoreCache ;
115- @params . Wait = options . Wait ;
116- }
84+ var @params = new ReloadCommandParameters ( context , options ? . IgnoreCache , options ? . Wait ) ;
11785
11886 return await Broker . ExecuteCommandAsync < ReloadCommand , NavigateResult > ( new ReloadCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
11987 }
12088
12189 public async Task SetViewportAsync ( BrowsingContext context , SetViewportOptions ? options = null )
12290 {
123- var @params = new SetViewportCommandParameters ( context ) ;
124-
125- if ( options is not null )
126- {
127- @params . Viewport = options . Viewport ;
128- @params . DevicePixelRatio = options ? . DevicePixelRatio ;
129- }
91+ var @params = new SetViewportCommandParameters ( context , options ? . Viewport , options ? . DevicePixelRatio ) ;
13092
13193 await Broker . ExecuteCommandAsync ( new SetViewportCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
13294 }
13395
13496 public async Task < IReadOnlyList < BrowsingContextInfo > > GetTreeAsync ( GetTreeOptions ? options = null )
13597 {
136- var @params = new GetTreeCommandParameters ( ) ;
137-
138- if ( options is not null )
139- {
140- @params . MaxDepth = options . MaxDepth ;
141- @params . Root = options . Root ;
142- }
98+ var @params = new GetTreeCommandParameters ( options ? . MaxDepth , options ? . Root ) ;
14399
144100 var getTreeResult = await Broker . ExecuteCommandAsync < GetTreeCommand , GetTreeResult > ( new GetTreeCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
145101
@@ -148,31 +104,14 @@ public async Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(GetTreeOption
148104
149105 public async Task < PrintResult > PrintAsync ( BrowsingContext context , PrintOptions ? options = null )
150106 {
151- var @params = new PrintCommandParameters ( context ) ;
152-
153- if ( options is not null )
154- {
155- @params . Background = options . Background ;
156- @params . Margin = options . Margin ;
157- @params . Orientation = options . Orientation ;
158- @params . Page = options . Page ;
159- @params . PageRanges = options . PageRanges ;
160- @params . Scale = options . Scale ;
161- @params . ShrinkToFit = options . ShrinkToFit ;
162- }
107+ var @params = new PrintCommandParameters ( context , options ? . Background , options ? . Margin , options ? . Orientation , options ? . Page , options ? . PageRanges , options ? . Scale , options ? . ShrinkToFit ) ;
163108
164109 return await Broker . ExecuteCommandAsync < PrintCommand , PrintResult > ( new PrintCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
165110 }
166111
167112 public async Task HandleUserPromptAsync ( BrowsingContext context , HandleUserPromptOptions ? options = null )
168113 {
169- var @params = new HandleUserPromptCommandParameters ( context ) ;
170-
171- if ( options is not null )
172- {
173- @params . Accept = options . Accept ;
174- @params . UserText = options . UserText ;
175- }
114+ var @params = new HandleUserPromptCommandParameters ( context , options ? . Accept , options ? . UserText ) ;
176115
177116 await Broker . ExecuteCommandAsync ( new HandleUserPromptCommand ( @params ) , options ) . ConfigureAwait ( false ) ;
178117 }
0 commit comments