tweak(mono-rt2): Use null coalescing for Write & WriteLine
Goal of this PR
This fixes an error if a null value is accidently passed into Debug.WriteLine
How is this PR achieving the goal
Using simple Null coalescing on the ToString call
This PR applies to the following area(s)
ScRT: C# v2
Successfully tested on
Tested the code seperate from the game, it prints nothing instead of causing a NullReferenceException.
Checklist
- [x] Code compiles and has been tested successfully.
- [x] Code explains itself well and/or is documented.
- [x] My commit message explains what the changes do and what they are for.
- [x] No extra compilation warnings are added by these changes.
This is a somewhat opiniated change, so not sure which behavior is more desirable, printing nothing or Debug.WriteLine causing an Exception.
Wouldn't it be better to print "null" instead of an empty string like in unity?
Wouldn't it be better to print "null" instead of an empty string like in unity?
Was thinking the same but would add some extra logic, and this reflects the default behavior of C#, Console.WriteLine(null) in C# prints nothing.
Ohh okay, I've been checking how it was done in V1 of C# and it doesn't have this problem because the function expects a string instead of an object, so if you want to print it yourself you have to do the .ToString() and therefore The error is in your code and not in the Debug.WriteLine function itself