public Expression <Func <TItem, bool> > GetPredicate(string identifier)
        {
            object identifierObj              = ConversionUtility.ConvertString(identifier, _propertyInfo.PropertyType);
            ParameterExpression param         = Expression.Parameter(typeof(TItem), "t");
            Expression          propertyExpr  = Expression.Property(param, _propertyInfo);
            BinaryExpression    predicateExpr = Expression.Equal(propertyExpr, Expression.Constant(identifierObj, _propertyInfo.PropertyType));

            return(Expression.Lambda <Func <TItem, bool> >(predicateExpr, param));
        }
 public Expression <Func <TItem, bool> > GetPredicate(string identifier)
 {
     try
     {
         TReturn convertedIdentifier = ConversionUtility.ConvertString <TReturn>(identifier);
         return(_predicateGetter(convertedIdentifier));
     }
     catch (Exception ex) when(ex is FormatException || ex is InvalidCastException)
     {
         // TODO hiding exception.. includes FormatException thrown in ConversionUtility
         return(null);
     }
 }
Ejemplo n.º 3
0
        public Expression GetFilterExpression(ParameterExpression itemPram, FilterComparisonOperator comparisonOperator, string valueString)
        {
            var getterMemberExpr = _reader.GetSelectExpression(itemPram);

            if (getterMemberExpr == null)
            {
                throw new InvalidCastException("Getter expression returned from IFieldReader is not of type MemberExpression.");
            }

            object             valueObj           = ConversionUtility.ConvertString(valueString, _reader.FieldType);
            ConstantExpression variableExpression = Expression.Constant(valueObj, _reader.FieldType); // TODO variable not constant?

            var        operatorMethod      = GetOperatorExpressionMethod(comparisonOperator);
            Expression predicateExpression = operatorMethod.Invoke(getterMemberExpr, variableExpression);

            return(predicateExpression);
        }
Ejemplo n.º 4
0
        public TItem GetAlreadyLoadedItem(string identifier)
        {
            var parameters = _getterMethod.GetParameters();

            Debug.Assert(parameters.Length == 1, "Should be exactly 1 parameter by the time we get here.");

            Type   paramType = parameters[0].ParameterType;
            object arg       = ConversionUtility.ConvertString(identifier, paramType);

            object methodValue = _getterMethod.Invoke(_instance, new object[] { arg });

            if (methodValue is TItem)
            {
                return((TItem)methodValue);
            }

            throw new IdentifierMethodNullException();
        }
        public void SetValue(TItem item, string identifier)
        {
            var newReference = ConversionUtility.ConvertString(identifier, _propertyInfo.PropertyType);

            _propertyInfo.SetValue(item, newReference);
        }