Timeline for Extension method to return a default value for any null value
Current License: CC BY-SA 3.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 6, 2014 at 19:34 | history | edited | Loren Shaw | CC BY-SA 3.0 |
added 1258 characters in body
|
| May 6, 2014 at 19:18 | vote | accept | Loren Shaw | ||
| May 6, 2014 at 18:14 | vote | accept | Loren Shaw | ||
| May 6, 2014 at 19:18 | |||||
| May 6, 2014 at 18:12 | answer | added | MAV | timeline score: 6 | |
| May 6, 2014 at 18:11 | vote | accept | Loren Shaw | ||
| May 6, 2014 at 18:14 | |||||
| May 6, 2014 at 18:10 | answer | added | Magus | timeline score: 5 | |
| May 6, 2014 at 16:28 | comment | added | Jeroen Vannevel |
I have my reservations about adding null and hoping for the best when it comes to value types. Perhaps using a small helper method might be warranted? I don't know how far your current usage is defined.
|
|
| May 6, 2014 at 15:58 | comment | added | Loren Shaw | That was a good catch Magus. Feel free to add that in the answer section and I'll upvote, and if no other responses given, accept | |
| May 6, 2014 at 15:46 | comment | added | Magus |
I'm slightly horrified that this is an extension on object and returns dynamic. You couldn't just use T? Then you'd get type inference at the call site, which might be nice.
|
|
| May 6, 2014 at 15:12 | history | edited | Loren Shaw | CC BY-SA 3.0 |
added 205 characters in body
|
| May 6, 2014 at 15:09 | comment | added | Loren Shaw | Me too, I was afraid of having to make this more complicated for value types. | |
| May 6, 2014 at 15:08 | comment | added | Jesse C. Slicer | Huh, cool. Not sure if that's defined behavior, but I like the behavior! | |
| May 6, 2014 at 15:08 | review | First posts | |||
| May 6, 2014 at 15:13 | |||||
| May 6, 2014 at 15:00 | comment | added | Loren Shaw | I attempted that, it assigned the default value for the value type. For example, int defaulted to 0, bool defaulted to false, etc. | |
| May 6, 2014 at 14:57 | comment | added | Jesse C. Slicer |
What will happen if the "first" constructor's parameter list has value types (such as int)? Will assigning null to it blow up?
|
|
| May 6, 2014 at 14:49 | history | asked | Loren Shaw | CC BY-SA 3.0 |