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
The Nodes field is declared as readonly instead of a property like other similar classes in this PR. This breaks consistency with the established pattern of using properties.
The System.Collections import is added but IEnumerable cast suggests it might be unnecessary. Verify if this import is actually needed or if explicit casting can be avoided.
The Write method throws NotImplementedException which could cause runtime errors if serialization is attempted. Consider implementing or documenting why serialization is not supported.
✅ Convert field to propertySuggestion Impact:The suggestion was directly implemented - the public readonly field was converted to a property with a getter as suggested
code diff:
- public readonly IReadOnlyList<Script.NodeRemoteValue> Nodes;+ public IReadOnlyList<Script.NodeRemoteValue> Nodes { get; }
The Nodes field should be a property with a getter to maintain consistency with other similar classes in the codebase. This ensures proper encapsulation and follows C# conventions.
Why: The suggestion correctly points out that Nodes is a public field, while other similar classes in the PR use properties, and changing it improves consistency.
Low
Learned best practice
Add null validation before usage
The code uses null-forgiving operator (!) without proper validation, which can lead to runtime exceptions. Add proper null checking before creating the GetTreeResult instance to ensure the deserialized contexts is not null.
public override GetTreeResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var doc = JsonDocument.ParseValue(ref reader);
var contexts = doc.RootElement.GetProperty("contexts").Deserialize(options.GetTypeInfo<IReadOnlyList<BrowsingContextInfo>>());
- return new GetTreeResult(contexts!);+ ArgumentNullException.ThrowIfNull(contexts);+ return new GetTreeResult(contexts);
}
Apply / Chat
Suggestion importance[1-10]: 6
__
Why:
Relevant best practice - Add null checks and validation for parameters, properties, and return values before using them to prevent NullReferenceException and other runtime errors. This includes checking dictionary keys exist before accessing them, validating required JSON properties, and ensuring objects are not null before method calls.
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
💥 What does this PR do?
Be more closer to low-level specification.
🔧 Implementation Notes
User is still able to use previous code, like
And additionally:
In general we reveal nested Enumerable property of
Enumerable Resultto support more properties in future.💡 Additional Considerations
🔄 Types of changes
PR Type
Enhancement
Description
Refactor BiDi result objects to expose nested properties
Make
GetTreeResultimplementIReadOnlyList<BrowsingContextInfo>Add
Contextsproperty toGetTreeResultfor better API accessUpdate multiple result classes to use public properties instead of private fields
Changes diagram
Changes walkthrough 📝
8 files
Refactor GetTreeResult to implement IReadOnlyListUpdate GetTreeAsync return typeUpdate GetTreeAsync method signatureAdd JSON converter for GetTreeResultExpose ClientWindows as public propertyExpose UserContexts as public propertyExpose Nodes as public propertyExpose Cookies as public property1 files
Register GetTreeResultConverter