internal T?ConvertNullable <T>( string prefix, string name, Items items, IEnumerable <Items> values, T?defaultValue) where T : struct { var pfx = prefix + name; if (!items.TryGetValue(pfx, out var value) || value == null) { return(defaultValue); } if (TypeConverters.TryGetValue(pfx, out var converter)) { return(converter.Convert <T>(value)); } converter = Options.Converters.First(x => x.CanConvert <T>(value)); TypeConverters.Add(pfx, converter); return(converter.Convert <T>(value)); }
public virtual TypeConverter TryGetTypeConverter(Type type) { TypeConverter returnValue; if (TypeConverters.TryGetValue(type, out returnValue)) { return(returnValue); } return(null); }
private static TypeConverter GetTypeConverter(TypeConverterAttribute attribute) { if (null == attribute) { return(null); } if (TypeConverters.TryGetValue(attribute, out TypeConverter converter)) { return(converter); } converter = (TypeConverter)Activator.CreateInstance( Type.GetType(attribute.ConverterTypeName)); TypeConverters[attribute] = converter; return(converter); }
public override void DeserializeOverride(StreamLimiter stream, EventShuttle eventShuttle) { var typeNode = (EnumTypeNode)TypeNode; var enumInfo = typeNode.EnumInfo; var value = Deserialize(stream, enumInfo.SerializedType, enumInfo.EnumValueLength); if (enumInfo.ValueEnums != null) { value = enumInfo.ValueEnums[(string)value]; } Func <object, object> converter; var underlyingValue = TypeConverters.TryGetValue(enumInfo.UnderlyingType, out converter) ? converter(value) : value; Value = Enum.ToObject(TypeNode.Type, underlyingValue); }
internal T Convert <T>( string prefix, string name, Items items, List <Items> values, T defaultValue) { var pfx = prefix + name; if (!items.TryGetValue(pfx, out var value) || value == null) { return(defaultValue); } if (TypeConverters.TryGetValue(pfx, out var converter)) { return(converter.Convert <T>(value)); } converter = Options.Converters.First(x => x.CanConvert <T>(value)); TypeConverters.Add(pfx, converter); return(converter.Convert <T>(value)); }