Hey all,
I have a need to convert a number of different objects and I'd like to avoid writing a converter class for each one. Each of the objects inherits from a base class and I need to use the Id to get the Description (which is handled in my call to my CacheManager).
For each class (I have about 30 of them) I have the following code written:
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Dictionary<int, string> codes = CacheManager.CodeLookup<CourtEventCode>();
int id = 0;
string result = string.Empty;
if (int.TryParse(value.ToString(), out id) && id > 0)
{
if (codes.ContainsKey(id))
{
result = codes[id];
}
else
{
result = "Unknown";
}
}
return result;
}
In the above example, CourtEventCode
represents the converter for this one class. Is there a way I can derive that class from the targetType input of IValueConverter.Convert instead of having to essentially copy-and-paste this class two dozen times?
Thanks in advance,
Sonny