public bool TryGetRegisteredType(string typeName, out Type type) { if (ReservedTypes.TryGetValue(typeName, out type)) { return(true); } lock (RegistrationLock) { return(TypeMap.TryGetValue(typeName, out type)); } }
public bool TypeIsRegistered <T>() { this.EnsureIsAssignableRegisteredType <T>(); string typeName = DataFactoryUtilities.GetResourceTypeName(typeof(T)); if (ReservedTypes.ContainsKey(typeName)) { return(true); } lock (RegistrationLock) { return(TypeMap.ContainsKey(typeName)); } }
/// <summary> /// Registers a type for conversion inside the TypeProperties of an ADF resource. /// </summary> /// <typeparam name="T">The type to register.</typeparam> /// <param name="force">If true, register the type <typeparamref name="T"/> /// even if it has already been registered.</param> /// <param name="wrapperType">The type to use for displaying any error messages.</param> public virtual void RegisterType <T>(bool force, Type wrapperType = null) { this.EnsureIsAssignableRegisteredType <T>(); Type type = typeof(T); string typeName = DataFactoryUtilities.GetResourceTypeName(type); string wrapperTypeName = wrapperType != null ? wrapperType.Name : typeof(TRegistered).Name; if (ReservedTypes.ContainsKey(typeName)) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "{0} type '{1}' cannot be locally registered because it has the same name as a built-in ADF {0} type.", wrapperTypeName, typeName)); } lock (RegistrationLock) { if (TypeMap.ContainsKey(typeName)) { if (force) { TypeMap.Remove(typeName); } else { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "A {0} type with the name '{1}' is already registered.", wrapperTypeName, typeName)); } } TypeMap.Add(typeName, type); } }