Beispiel #1
0
        protected override Expression BuildExpression(FilterParameters parameters)
        {
            var systemEvent        = parameters.GetParameter(typeof(SystemEvent));
            var propertyName       = ExtendedProperties.GetExtendedProperty("property");
            var propertyExpression = Expression.Property(systemEvent, propertyName);

            return(expressionBuilder.Invoke(
                       ConvertPropertyValueIfRequired(propertyExpression),
                       GetConvertedValue(propertyExpression.Type)
                       ));
        }
Beispiel #2
0
        protected Expression GetConvertedValue(Type targetType)
        {
            var value = ExtendedProperties.GetExtendedProperty("value") ?? String.Empty;

            if (targetType.IsEnum)
            {
                return(Expression.Constant(((IConvertible)Enum.Parse(targetType, value, true)).ToType(targetType.GetEnumUnderlyingType(), CultureInfo.InvariantCulture)));
            }

            return(typeof(IConvertible).IsAssignableFrom(targetType)
                        ? Expression.Constant(((IConvertible)value).ToType(targetType, CultureInfo.InvariantCulture))
                        : Expression.Convert(Expression.Constant(value), targetType) as Expression);
        }