src/MVCContrib/Binders/DerivedTypeModelBinderCache.cs
/// <summary>
/// Registers the attached set of derived types by the indicated base type
/// </summary>
/// <param name="baseType">base type that will be encountered by the binder where an alternate value should be used</param>
/// <param name="derivedTypes">an enumerable set of types to be considered for binding</param>
Registers the attached set of derived types by the indicated base type
Registers the attached set of derived types by the indicated base type
public static bool RegisterDerivedTypes(Type baseType, IEnumerable<Type> derivedTypes)
		{
			try
			{
				_typeCache.Add(baseType, derivedTypes);
			}
			catch (ArgumentException)
			{
				return false;
			}
			foreach (var item in derivedTypes)
			{
				var currentItem = item;
				var encryptedName = EncryptStringToBase64(currentItem.FullName);
				_hashToTypeDictionary.AddOrUpdate(encryptedName, name => currentItem,
				                               (name, itemValue) => currentItem);
				_typeToHashDictionary.AddOrUpdate(currentItem, type => encryptedName, (type, name) => encryptedName);
			}
			ModelBinders.Binders.Add(baseType, new DerivedTypeModelBinder());
			return true;
		}
public static bool RegisterDerivedTypes ( Type baseType , IEnumerable < Type > derivedTypes ) { try { _typeCache . Add ( baseType , derivedTypes ) ; } catch ( ArgumentException ) { return false ; } foreach ( var item in derivedTypes ) { var currentItem = item ; var encryptedName = EncryptStringToBase64 ( currentItem . FullName ) ; _hashToTypeDictionary . AddOrUpdate ( encryptedName , name => currentItem , ( name , itemValue ) => currentItem ) ; _typeToHashDictionary . AddOrUpdate ( currentItem , type => encryptedName , ( type , name ) => encryptedName ) ; } ModelBinders . Binders . Add ( baseType , new DerivedTypeModelBinder ( ) ) ; return true ; }
Registers the attached set of derived types by the indicated base type
Registers the attached set of derived types by the indicated base type
// register the types based on the base type // this step is needed to make sure the closure behaves properly // register the base type with the derived type modelbinder for binding purposes
baseType
Type
base type that will be encountered by the binder where an alternate value should be used
base type that will be encountered by the binder where an alternate value should be used
derivedTypes
IEnumerable<Type>
an enumerable set of types to be considered for binding
an enumerable set of types to be considered for binding