[dotnet] [bidi] Hide Broker as internal implementation by nvborisenko · Pull Request #16982 · SeleniumHQ/selenium
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Relax result type constraintRelax the generic constraint on dotnet/src/webdriver/BiDi/Module.cs [33-35] protected Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo)
where TCommand : Command
- where TResult : EmptyResult
+ where TResult : class
Suggestion importance[1-10]: 10__ Why: The suggestion correctly identifies a critical compilation error. The generic constraint | High |
Fix array literal syntaxReplace the invalid array literal syntax dotnet/src/webdriver/BiDi/Broker.cs [155] -var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false); +var subscribeResult = await _bidi.SessionModule.SubscribeAsync(new[] { eventName }, new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false);
Suggestion importance[1-10]: 10__ Why: The suggestion correctly identifies invalid C# syntax ( | High | |
Synchronize handler additionWrap the addition of an event handler to the dotnet/src/webdriver/BiDi/Broker.cs [153-157] -var handlers = _eventHandlers.GetOrAdd(eventName, (a) => []); +var handlers = _eventHandlers.GetOrAdd(eventName, _ => new List<EventHandler>()); ... -handlers.Add(eventHandler); +lock (handlers) +{ + handlers.Add(eventHandler); +}
Suggestion importance[1-10]: 8__ Why: This suggestion correctly identifies a potential race condition when adding event handlers from multiple threads. Using a | Medium | |
| Learned best practice |
Validate inputs before useValidate dotnet/src/webdriver/BiDi/Module.cs [40-52] protected Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Action<TEventArgs> action, SubscriptionOptions? options, JsonTypeInfo<TEventArgs> jsonTypeInfo)
where TEventArgs : EventArgs
{
+ ArgumentException.ThrowIfNullOrWhiteSpace(eventName);
+ ArgumentNullException.ThrowIfNull(action);
+ ArgumentNullException.ThrowIfNull(jsonTypeInfo);
+
var eventHandler = new SyncEventHandler<TEventArgs>(eventName, action);
return Broker.SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo);
}
public Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Func<TEventArgs, Task> func, SubscriptionOptions? options, JsonTypeInfo<TEventArgs> jsonTypeInfo)
where TEventArgs : EventArgs
{
+ ArgumentException.ThrowIfNullOrWhiteSpace(eventName);
+ ArgumentNullException.ThrowIfNull(func);
+ ArgumentNullException.ThrowIfNull(jsonTypeInfo);
+
var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func);
return Broker.SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo);
}
Suggestion importance[1-10]: 6__ Why: | Low |
| General |
Make subscription helper method protectedChange the dotnet/src/webdriver/BiDi/Module.cs [47-52] -public Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Func<TEventArgs, Task> func, SubscriptionOptions? options, JsonTypeInfo<TEventArgs> jsonTypeInfo) +protected Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Func<TEventArgs, Task> func, SubscriptionOptions? options, JsonTypeInfo<TEventArgs> jsonTypeInfo) where TEventArgs : EventArgs { var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func); return Broker.SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo); }
Suggestion importance[1-10]: 5__ Why: The suggestion correctly identifies an access modifier inconsistency between two similar helper methods, and changing it to | Low |
| ||