The Daily WTF

CodeSOD: Serial Properties

Jan discovered an unusual C# code where the property's getter is protected and serializes the value as JSON. This raises concerns as the getter is not a true getter but a JSON serializer, and the property is a string, making the serialization redundant. Moreover, an extension method, IsNotValid(), is applied to the string, which is an unexpected use of extension methods. This pattern of adding complex code to getters and setters is common in .NET languages, leading to unexpected behaviors. Assigning the property's value effectively serializes it to JSON, which can be surprising when the property data is a string. Jan emphasizes that this is a common booby trap in his application, showcasing the need for caution when using such code patterns.
favicon
thedailywtf.com
thedailywtf.com