Пример #1
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="classProperty"></param>
            /// <returns></returns>
            public static Action <TEntity, object> GetFunc(ClassProperty classProperty)
            {
                if (classProperty == null)
                {
                    return(null);
                }

                if (cache.TryGetValue(classProperty.GetHashCode(), out var func) == false)
                {
                    if (classProperty != null)
                    {
                        var entity    = Expression.Parameter(typeof(TEntity), "entity");
                        var value     = Expression.Parameter(typeof(object), "value");
                        var converted = Expression.Convert(value, classProperty.PropertyInfo.PropertyType);
                        var body      = (Expression)Expression.Call(entity, classProperty.PropertyInfo.SetMethod, converted);

                        func = Expression
                               .Lambda <Action <TEntity, object> >(body, entity, value)
                               .Compile();
                    }

                    cache.TryAdd(classProperty.GetHashCode(), func);
                }
                return(func);
            }
Пример #2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="classProperty"></param>
            /// <returns></returns>
            public static Func <TEntity, TResult> GetFunc(ClassProperty classProperty)
            {
                if (cache.TryGetValue(classProperty.GetHashCode(), out var func) == false)
                {
                    var typeOfEntity = typeof(TEntity);
                    var entity       = Expression.Parameter(typeOfEntity, "entity");
                    var body         = Expression.Convert(Expression.Call(entity, classProperty.PropertyInfo.GetMethod), typeof(TResult));

                    func = Expression
                           .Lambda <Func <TEntity, TResult> >(body, entity)
                           .Compile();

                    cache.TryAdd(classProperty.GetHashCode(), func);
                }
                return(func);
            }
Пример #3
0
            public static Action <TEntity, object> GetFunc(ClassProperty property)
            {
                var func = (Action <TEntity, object>)null;

                // Try get from cache
                if (m_cache.TryGetValue(property.GetHashCode(), out func) == false)
                {
                    // Parameters
                    var entity = Expression.Parameter(typeof(TEntity), "entity");
                    var value  = Expression.Parameter(typeof(object), "value");

                    // Set the body
                    var converted = Expression.Convert(value, property.PropertyInfo.PropertyType);
                    var body      = (Expression)Expression.Call(entity, property.PropertyInfo.SetMethod, converted);

                    // Set the function value
                    func = Expression
                           .Lambda <Action <TEntity, object> >(body, entity, value)
                           .Compile();
                }

                // return the function
                return(func);
            }
Пример #4
0
 public override int GetHashCode()
 {
     return((element != null ? element.GetHashCode() : 0)
            ^ (vmProperty != null ? vmProperty.GetHashCode() : 0)
            ^ (vmMethod != null ? vmMethod.GetHashCode() : 0));
 }