C# properties and type safety
-
Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:
[XmlIgnore]
public DateTime? SomeProperty
{
get;set;
}public String SomePropertyXml
{
get
{
return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
}
set
{
if (String.IsNullOrEmpty(value as String))
SomeProperty = null;
else
SomeProperty = XmlConvert.ToTimeSpan(value);
}
}Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:
[XmlIgnore]
public DateTime? SomeProperty
{
get;set;
}public String SomePropertyXml
{
get
{
return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
}
set
{
if (String.IsNullOrEmpty(value as String))
SomeProperty = null;
else
SomeProperty = XmlConvert.ToTimeSpan(value);
}
}Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
Oh, that's not even strange in my codebase. We have many nullable DateTime, as optional parameters/informations. For instance, we have a kind of 'last access date' for files, which is stored as a Nullable.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:
[XmlIgnore]
public DateTime? SomeProperty
{
get;set;
}public String SomePropertyXml
{
get
{
return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
}
set
{
if (String.IsNullOrEmpty(value as String))
SomeProperty = null;
else
SomeProperty = XmlConvert.ToTimeSpan(value);
}
}Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Clearly your predecessor did not understand either the type system nor TimeSpans. :wtf:
Just because the code works, it doesn't mean that it is good code.
Likely both.
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking
-
Oh, that's not even strange in my codebase. We have many nullable DateTime, as optional parameters/informations. For instance, we have a kind of 'last access date' for files, which is stored as a Nullable.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
Ok, I'll be more precise then. I'm working on a media player application, in which you get a list of media files from a webservice. The DateTime of last playback is null until you have actually played the file. Does that make sense now?
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:
[XmlIgnore]
public DateTime? SomeProperty
{
get;set;
}public String SomePropertyXml
{
get
{
return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
}
set
{
if (String.IsNullOrEmpty(value as String))
SomeProperty = null;
else
SomeProperty = XmlConvert.ToTimeSpan(value);
}
}Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
I've seen stranger DateTime usage in the Web Service I'm working on. We use a nullable type too, but in this case it was a WTF because Microsoft handed us a WTF with WCF. Stranger is our code that handles a DataSet which has a DateTime column as part of an incoming web request. Whenever we get new developers on board, we watch them when they come across this piece of code. Some of them slump down in their desks and go into a trance, while some quickly walk away and wash their hands with plenty of SOAP. :)
SG Aham Brahmasmi!