I think I've come across a better solution (or at least one that I'm happier with) to this problem. Turns out that the KnownType attribute can take a method name instead of a type. The type it's applied to then has to implement a static method with that name that returns an array of Type. That method can then decide which types to return. So I could do something like this
[DataContract]
[KnownType("CheckForConfiguredOverrides")]
public class UserBase
{
[DataMember]
public string FirstName;
public string LastName;
public static Type[] CheckForConfiguredOverrides()
List<Type> result = new List<Type>();
string thisTypeName = typeof(UserBase).FullName;
string overrideType = System.Configuration.ConfigurationManager.AppSettings.Get(thisTypeName);
if (!string.IsNullOrEmpty(overrideType))
Type type = Type.GetType(overrideType);
if (type != null) result.Add(type);
}
return result.ToArray();
Then in the config file (this ultimately will use our distributed configuration service) I add
<appSettings>
<add key="UserBaseType.UserBase" value="UserBaseType.BankUser"/>
</appSettings>
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Patrick Cauldwell
E-mail