-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix casting of list of textruns #333
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #333 +/- ##
===================================
Coverage 80% 80%
===================================
Files 97 97
Lines 4960 4971 +11
Branches 886 888 +2
===================================
+ Hits 4011 4023 +12
+ Misses 754 753 -1
Partials 195 195
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Would direct casting not work if we explicitly set an empty array as the default value? |
@@ -33,7 +33,7 @@ public RichTextOptions(RichTextOptions options) | |||
/// </summary> | |||
public new IReadOnlyList<RichTextRun> TextRuns | |||
{ | |||
get => (IReadOnlyList<RichTextRun>)base.TextRuns; | |||
get => base.TextRuns.Cast<RichTextRun>().ToList(); |
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 creates a copy and in my understanding Cast
should also fail since the default instance is has the property assigned to TextRun[]
not RichTextRun[]
.
Would direct casting not work if we explicitly set an empty array as the default value?
That would be a better solution IMO, but it would allow bringing the object into an invalid state by downcasting RichTextOptions
to TextOptions
. It is an unusual but valid code.
RichTextOptions a = new(font);
Foo(a);
void Foo(TextOptions b) => b.TextRuns = new TextRun[0];
IReadOnlyList<RichTextRun> runs = a.TextRuns; // exception
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 think we'd probably fix that with some sort of generic pattern in the future but for now our options are limited.
Thanks @stefannikolei for this. I'm going to close it though as I've added a fix to #335 that assigns the empty array. |
Directly casting is not possible. That's why using the Cast method is the easiest way
Fixes #332