示例#1
0
        /// <summary>
        /// Map a external field (name) to a property (expression)
        /// </summary>
        /// <param name="fieldKey">The field id sent by the api client (e.g. CityName)</param>
        /// <param name="fieldExpression">The sort delegate (Lambda expression)</param>
        protected void MapSort(string fieldKey, Expression <Func <T, object> > fieldExpression)
        {
            // Hack EF object expressions
            LambdaExpression lambda = fieldExpression.Normalize();

            if (!SortMappings.ContainsKey(fieldKey))
            {
                SortMappings.Add(fieldKey, lambda);
            }
        }
示例#2
0
        /// <summary>
        /// Mapeia um identificador de campo (nome) à uma propriedade (expressão)
        /// </summary>
        /// <param name="fieldKey">Identificador do campo</param>
        /// <param name="fieldExpression">Expressão da propriedade (LAMBDA)</param>
        public void MapSort(string fieldKey, Expression <Func <EntityType, object> > fieldExpression)
        {
            LambdaExpression lambda = fieldExpression;

            // Expressoes lambda com tipos diferente de string sao construidos com o Metodo "Convert"
            // Esse algoritmo remove essa chamada da expressao, deixando a chamada pura à propriedade
            // Exemplo: DE: i => Convert(i.Active) | PARA: i => i.Active
            var unary = fieldExpression.Body as UnaryExpression;

            if (unary != null)
            {
                lambda = Expression.Lambda(unary.Operand, fieldExpression.Parameters);
            }

            if (!SortMappings.ContainsKey(fieldKey))
            {
                SortMappings.Add(fieldKey, lambda);
            }
        }