/// <summary> /// Converts enum to its map value. /// </summary> /// <param name="value">Value to convert.</param> /// <returns>Mapped value.</returns> public object EnumToValue([NotNull] Enum value) { Code.NotNull(value, nameof(value)); var toType = ConvertBuilder.GetDefaultMappingFromEnumType(this, value.GetType()); return(Converter.ChangeType(value, toType, this)); }
public void ConvertNullableEnum() { var schema = new MappingSchema("2"); Assert.That(schema.GetDefaultValue(typeof(Enum1?)), Is.Null); var mapType = ConvertBuilder.GetDefaultMappingFromEnumType(schema, typeof(Enum1?)); Assert.That(mapType, Is.EqualTo(typeof(int?))); var convertedValue = Converter.ChangeType(null, mapType, schema); Assert.IsNull(convertedValue); }
private static void Init() { var expr = ConvertBuilder.GetConverter(null, typeof(TFrom), typeof(TTo)); _expression = (Expression <Func <TFrom, TTo> >)expr.Item1; var rexpr = (Expression <Func <TFrom, TTo> >)expr.Item1.Transform(e => e is DefaultValueExpression ? e.Reduce() : e); _lambda = rexpr.Compile(); }
public LambdaInfo Create([CanBeNull] MappingSchema mappingSchema, [NotNull] Type from, [NotNull] Type to) { var ex = ConvertBuilder.GetConverter(mappingSchema, from, to); var lm = ex.Item1.Compile(); var ret = new LambdaInfo(ex.Item1, ex.Item2, lm, ex.Item3); Set(_expressions, from, to, ret); return(ret); }
/// <summary> /// Converts enum to its map value. /// </summary> /// <param name="value">Value to convert.</param> /// <returns>Mapped value.</returns> public object EnumToValue(Enum value) { var toType = ConvertBuilder.GetDefaultMappingFromEnumType(this, value.GetType()); return(Converter.ChangeType(value, toType, this)); }