/// <summary> /// Checks for a type converter (if one exists). /// 1) Checks for a converter registered for the current columns data type. /// 2) Checks to see if a converter is registered for all enums (type of Enum) if the current column is an enum. /// 3) Checks to see if a converter is registered for all objects (type of Object). /// </summary> /// <param name="dataMap">The current data map.</param> /// <returns>Returns an IConverter object or null if one does not exist.</returns> internal IConverter GetConverter(Type dataType) { if (TypeConverters.ContainsKey(dataType)) { // User registered type converter return(TypeConverters[dataType]); } if (TypeConverters.ContainsKey(typeof(Enum)) && dataType.IsEnum) { // A converter is registered to handled enums return(TypeConverters[typeof(Enum)]); } if (TypeConverters.ContainsKey(typeof(object))) { // User registered default converter return(TypeConverters[typeof(object)]); } // No conversion return(null); }
private static void LoadTypeConverters(Assembly assem) { if (TypeConverters == null) { TypeConverters = new Dictionary <Type, IList <TypeConverter> >(); } var tcType = typeof(TypeConverter); var types = LoadedTypes[assem].Where(t => tcType.IsAssignableFrom(t) && t != tcType).ToList(); foreach (var t in types) { var tc = Activator.CreateInstance(t) as TypeConverter; if (!TypeConverters.ContainsKey(tc.FromType)) { TypeConverters.Add(tc.FromType, new List <TypeConverter>()); } TypeConverters[tc.FromType].Add(tc); } }