You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review
Null Reference The current field is marked as nullable but there's no null check in the CurrentPlatform property before dereferencing. While the null-coalescing operator is used, it's good practice to validate this critical platform-dependent code.
Platform Detection The platform detection logic in the private constructor doesn't handle all possible PlatformID values. Some modern Windows versions might not be properly detected with the current version checks.
Error Handling The FromString method silently falls back to PlatformType.Any when parsing fails. Consider logging a warning or throwing an exception for invalid platform names in debug builds.
Add support for Mono Unix platform detection to ensure consistent platform handling
The platform detection in the constructor should handle the Mono Unix platform (PlatformID 128) to maintain consistency with other parts of the codebase.
+const PlatformID PlatformIDMonoUnix = (PlatformID)128;
switch (Environment.OSVersion.Platform)
{
case PlatformID.Win32NT:
if (this.MajorVersion == 5)
{
this.PlatformType = PlatformType.XP;
}
else if (this.MajorVersion == 6)
{
this.PlatformType = PlatformType.Vista;
}
else
{
this.PlatformType = PlatformType.Windows;
}
break;
case PlatformID.MacOSX:
this.PlatformType = PlatformType.Mac;
break;
case PlatformID.Unix:
+ case PlatformIDMonoUnix:
this.PlatformType = PlatformType.Unix;
break;
}
Apply this suggestion
Suggestion importance[1-10]: 8
Why: The suggestion ensures consistent platform detection by adding support for Mono Unix (PlatformID 128), aligning with the changes made in other files and preventing potential platform detection issues.
8
Explicitly handle all platform types in switch expression to prevent potential bugs
The switch expression in IsPlatformType method should handle all possible PlatformType enum values explicitly. Add cases for Mac and Unix to avoid potential bugs when new platform types are added.
return compareTo switch
{
PlatformType.Any => true,
PlatformType.Windows => this.PlatformType is PlatformType.Windows or PlatformType.XP or PlatformType.Vista,
PlatformType.Vista => this.PlatformType is PlatformType.Windows or PlatformType.Vista,
PlatformType.XP => this.PlatformType is PlatformType.Windows or PlatformType.XP,
PlatformType.Linux => this.PlatformType is PlatformType.Linux or PlatformType.Unix,
+ PlatformType.Mac => this.PlatformType == PlatformType.Mac,+ PlatformType.Unix => this.PlatformType == PlatformType.Unix,
_ => this.PlatformType == compareTo,
};
Apply this suggestion
Suggestion importance[1-10]: 7
Why: The suggestion improves code maintainability and robustness by explicitly handling Mac and Unix cases in the switch expression, reducing the risk of bugs when new platform types are added.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Adds Nullable Reference Type annotations to the
Platformtype, as well as modernizes the code surrounding the platform handling.t
Motivation and Context
Contributes to #14640
Types of changes
Checklist
PR Type
enhancement
Description
Platformclass, improving code safety and clarity.Platformclass to use auto-properties and modern C# features like switch expressions.ChromiumDriverServiceandFirefoxDriverServiceby using thePlatformIDenum instead of integer constants.FromStringmethod in thePlatformclass to useEnum.TryParse, enhancing robustness.Changes walkthrough 📝
ChromiumDriverService.cs
Simplify platform detection using PlatformID enumdotnet/src/webdriver/Chromium/ChromiumDriverService.cs
PlatformIDenum for Mono Unix.FirefoxDriverService.cs
Simplify platform detection using PlatformID enumdotnet/src/webdriver/Firefox/FirefoxDriverService.cs
PlatformIDenum for Mono Unix.Platform.cs
Add nullable annotations and modernize Platform classdotnet/src/webdriver/Platform.cs
Platformclass to use auto-properties.IsPlatformTypemethod using switch expressions.FromStringmethod withEnum.TryParse.