I have a general class, which is a document that can currently be of only two types. Type1 or Type2. Most methods and properties work fine for both types, but the name is different. What am I wondering if there is a better way to handle this? Thank!!
[XmlIgnore]
public string DocumentType
{
get
{
return typeof(T).Name;
}
}
[XmlIgnore]
public string DocumentTitle
{
get
{
string retval = string.Empty;
Object obj = Document;
switch (DocumentType)
{
case "Type1":
retval = ((Type1)obj).title.Text;
break;
case "Type2":
retval = ((Type2)obj).Title;
break;
}
return retval;
}
}
Type1 and Type2 were generated using xsd.exe, so I'm embarrassed to change them, although perhaps adding the readonly xml ignored property to get the header in both Type1 and Type2, which is consistent?
source
share