internal EnumMapping ImportEnum(Type type) { EnumMapping mapping = null; if (!EnumMapping.IsMappableEnum(type)) { throw Error.Argument("type", "Type {0} is not a mappable enumeration", type.Name); } lock (lockObject) { mapping = FindEnumMappingByType(type); if (mapping != null) { return(mapping); } mapping = EnumMapping.Create(type); _enumMappingsByType[type] = mapping; Message.Info("Created Enum mapping for newly encountered type {0}", type.Name); } return(mapping); }
public static object ParseLiteral(string rawValue, Type enumType) { EnumMapping fieldInfo = null; lock (_cacheLock) { if (!_cache.TryGetValue(enumType, out fieldInfo)) { fieldInfo = EnumMapping.Create(enumType); _cache.Add(enumType, fieldInfo); } } return((object)fieldInfo.ParseLiteral(rawValue)); //foreach (var enumValue in fieldInfo) //{ // var attr = ReflectionHelper.GetAttribute<EnumLiteralAttribute>(enumValue); // if (attr != null) // { // if (attr.Literal == rawValue) // { // return (T)enumValue.GetValue(null); // } // } //} //return null; }
private static EnumMapping GetEnumMapping(Type enumType) { EnumMapping fieldInfo = null; lock ( _cacheLock ) { if (!_cache.TryGetValue(enumType, out fieldInfo)) { fieldInfo = EnumMapping.Create(enumType); _cache.Add(enumType, fieldInfo); } } return(fieldInfo); }