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.
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.
This should fix the trace in the non IConvertible case
04d0979 to
11dbb2e
Compare
|
Thanks for working on this! |
11dbb2e to
f6e78ce
Compare
JeremyKuhne
left a comment
There was a problem hiding this comment.
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.
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.
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.
It's better to use pattern matching here. if (GetTargetFrameworkProvider(manager, instance) is TypeDescriptionProvider targetProvider)
There was a problem hiding this comment.
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.
Why change this to ReadOnlySpan?
There was a problem hiding this comment.
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
JeremyKuhne
left a comment
There was a problem hiding this comment.
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