-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable nullability in CodeDomSerializerBase #9099
Conversation
893a2c0
to
04d0979
Compare
{ | ||
if (statement is CodeMethodReturnStatement cmrs) | ||
{ | ||
DeserializeExpression(manager, null, ces.Expression); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looked a lot like a bug
@@ -1242,11 +1165,11 @@ protected object DeserializeExpression(IDesignerSerializationManager manager, st | |||
// | |||
for (int i = 0; i < indexes.Length; i++) | |||
{ | |||
IConvertible index = DeserializeExpression(manager, name, arrayIndexerEx.Indices[i]) as IConvertible; | |||
object? index = DeserializeExpression(manager, name, arrayIndexerEx.Indices[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the trace in the non IConvertible case
04d0979
to
11dbb2e
Compare
Thanks for working on this! |
11dbb2e
to
f6e78ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, looks really good! I think there is a bit more opportunity to use pattern matching. See my comments.
{ | ||
typename.Append(','); | ||
typeName.Append('['); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be further improved by aggregating these Append calls into a single Append($',[{GetTypeNameFromCodeTypeReferenceHelper(manager, childref, typeName)}],)
. Same for other cases where we're making multiple calls in a row.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. In the end there weren't many opportunities to do so, as line 93 isn't a direct Append
call
@@ -194,7 +180,7 @@ protected static Type GetReflectionTypeHelper(IDesignerSerializationManager mana | |||
Type type = instance.GetType(); | |||
if (type.IsValueType) | |||
{ | |||
TypeDescriptionProvider targetProvider = GetTargetFrameworkProvider(manager, instance); | |||
TypeDescriptionProvider? targetProvider = GetTargetFrameworkProvider(manager, instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use pattern matching here. if (GetTargetFrameworkProvider(manager, instance) is TypeDescriptionProvider targetProvider)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the opportunity to move this logic to a helper to reduce code duplication
...Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerBase.cs
Outdated
Show resolved
Hide resolved
private static object ExecuteBinaryOperator(IConvertible left, IConvertible right, CodeBinaryOperatorType op) | ||
{ | ||
TypeCode leftType = left.GetTypeCode(); | ||
TypeCode rightType = right.GetTypeCode(); | ||
|
||
// The compatible types are listed in order from lowest bitness to highest. We must operate on the highest bitness to keep fidelity. | ||
TypeCode[] compatibleTypes = new TypeCode[] | ||
ReadOnlySpan<TypeCode> compatibleTypes = new TypeCode[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this to ReadOnlySpan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that dotnet/runtime#60948 is closed it should remove the array allocation
...mitives/src/System/ComponentModel/Design/Serialization/DesignerSerializationManagerHelper.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for this!
What is left to fully address #8342? |
There are quite a lot of files that still need annotating. I count 192 as of current main branch. |
This PR is pretty big, apologies for that. It enables nullability in CodeDomSerializerBase to get one foot in the door to annotate more serializers down the road,
One issue I had doing this is the lack of annoations in System.CodeDom (see dotnet/runtime#41720, dotnet/runtime#78036)
Contributes to #8342
Proposed changes
Each change is its own commit.
Microsoft Reviewers: Open in CodeFlow