[NET10.0] Annotate converters for nullability 4/n#29549
[NET10.0] Annotate converters for nullability 4/n#29549rmarinho merged 3 commits intodotnet:net10.0from
Conversation
|
Hey there @@MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
| _parts = css!.Replace("\r\n", "") | ||
| #else | ||
| _parts = css.Replace("\r\n", "", StringComparison.Ordinal) | ||
| _parts = css!.Replace("\r\n", "", StringComparison.Ordinal) |
There was a problem hiding this comment.
For some reason string.IsNullOrWhiteSpace(css) is not enough for the analyzer to realize that css is not null at this point. (if (css is null || css = "") would be an alternative to avoid the ! operator.
| if (strValue.StartsWith(Rgb, StringComparison.InvariantCulture) | ||
| || strValue.StartsWith(Rgba, StringComparison.InvariantCulture) | ||
| || strValue.StartsWith(Hsl, StringComparison.InvariantCulture) | ||
| || strValue.StartsWith(Hsla, StringComparison.InvariantCulture)) |
There was a problem hiding this comment.
StringComparison.InvariantCulture was missing for Hsla, so I added it.
|
@MartyIX net10 android needs Android 35 api? we also recommend jdk 21. |
|
I do have JDK 21 installed on my machine.
I don't know. I just ran |
|
@MartyIX I ran into the same build issue. In my case, I had updated my System Environment Variables to set — primarily to get Appium working. After that, I started encountering build errors when trying to build MAUI code. It turns out that the MAUI/Gradle build process checks for the SDK at: which is where Visual Studio installs the SDK by default via the Android SDK Manager. To resolve the issue, I simply removed the manually set environment variables, and the build worked again without errors. Hope this helps. |
|
Much appreciated! My setup seems to be a bit different. I'm trying to repair my Visual Studio at the moment, if it is not related to it. It's a wild guess. Otherwise, my setup looks pretty normal. Not sure what might be wrong. But I'll figure it out... sooner or later. |
199468b to
e694190
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Sorry it wasn't a question, you need to install api 35 of android |
|
@bhavanesh2001 I copied |
| } | ||
|
|
||
| pathFigure.Segments.Add(new LineSegment | ||
| pathFigure!.Segments.Add(new LineSegment |
There was a problem hiding this comment.
can we just return if it s null ?
There was a problem hiding this comment.
It is my understanding that it would be better to:
if (pathFigure is null)
{
ThrowBadToken();
}
else
{
pathFigure.Segments.Add(new LineSegment
{
Point = lastPoint
});
}because one can get here presumably only if the parsed path string is somehow invalid (there is no 'm' / 'M' specified.
Would it make sense to you as an alternative?
rmarinho
left a comment
There was a problem hiding this comment.
Can we add a test passing null to these converters to make sure it actually works and doesn t break ?
e694190 to
af9d132
Compare
I added tests which show that converters behave differently but the tests hopefully make sure that they behave the same as before. |
| public class PathFigureCollectionConverterTests | ||
| { | ||
| private readonly PathFigureCollectionConverter _pathFigureCollectionConverter = new(); | ||
| private readonly PathFigureCollectionConverter _converter = new(); |
There was a problem hiding this comment.
Renamed so it's unified with other tests.
| } | ||
|
|
||
| void ThrowBadToken() | ||
| Exception GetBadTokenException() |
There was a problem hiding this comment.
Modified to return the exception as throw GetBadTokenException() behaves much better with respect to .NET analyzers (detection of dead code, etc.)
| public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
| public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) | ||
| { | ||
| var strValue = value?.ToString(); |
There was a problem hiding this comment.
In an ideal world, we would go with
| var strValue = value?.ToString(); | |
| var strValue = value.ToString(); |
but that would change behavior. This approach is used even in other converters.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| public class BrushTypeConverterUnitTests : BaseTestFixture | ||
| { | ||
| BrushTypeConverter _converter; | ||
| private readonly BrushTypeConverter _converter = new(); |
There was a problem hiding this comment.
OK.
IMO there should be an analyzer checking it. So much time of humans and machines is lost on this.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
Follow-up to #29314. See #28244 (comment) for details on motivation.
Issues Fixed
Contributes to #28860