In the code base that I supported, I found this exact class inserted below. The property logPath getsdoes some work. I think it’s better to do the job in set- this will be done only once. However, partly because this is how the class is written, partly because this property is converted to xml, and partly because I am afraid that I might miss something in the debugger, I have doubts.
Also, if the element never existed in xml, and this turned out to be optional, I think I will get zero for the value. I might want to distinguish between the absence of an element and getting an empty value. I suggest that I may have a private member boolthat can help me discover this - this will be an argument for working in set, not get. Thus, code optimizers work these days, so performance is rarely a real problem. It is more likely to "figure it out and not think about it later." This is just one example, and some massaging properties often do.
Could you say that it is always better to work in set? In get? It depends? Mixed style won't bother you with one bit as long as it works?
Thank.
namespace MyNamespace
{
using System;
using System.Xml.Serialization;
public class LoggingListener
{
private string logPathValue;
[XmlAttribute("logPath")]
public string LogPath
{
get
{
return this.logPathValue == null ?
String.Empty : this.logPathValue;
}
set
{
this.logPathValue = value;
}
}
}
}
: ... , .