Re:Using implicit operator overloads to keep your C# API dis...
by danbruc on Friday May 09, 2014 @12:46PM
(#7721832)
I would prefer static read-only properties over methods and always return the same instance.
It becomes a bit inconsistent because of the method for the custom case but I would accept that for less noise in the common case.
[ Parent
| on HN ]
Re:Using implicit operator overloads to keep your C# API dis...
by klauserc on Friday May 09, 2014 @02:17PM
(#7722439)
It's a struct. It will always be returned by value.
Furthermore, the struct has a single Int32 field. The code generated for "new BookingTypeId(3)" is about the same as for "3".
Re:Using implicit operator overloads to keep your C# API dis...
by kevingadd on Friday May 09, 2014 @01:20PM
(#7722043)
If the field is readonly why did you make the property in the first place? Just do public static readonly BookingTypeId Gold. It's equivalent.
Re:Using implicit operator overloads to keep your C# API dis...
by Locke1689 on Friday May 09, 2014 @01:44PM
(#7722215)
If this is public surface area, the change from field to property is a binary break.
Re:Using implicit operator overloads to keep your C# API dis...
by danbruc on Friday May 09, 2014 @02:11PM
(#7722407)
...and you never know when you might have to add something to the getter. It's the same reason why you usually prefer properties over public fields even if there is no logic in the accessors. Similarly you usually want to expose constants by wrapping them in a read-only property because otherwise the compiler will inline the constant and you can not change it without recompiling all dependencies.