private Expression ForProperty(Expression cur, MemberInfo property) { cur = property.ValueFromExpression(cur); var variable = Expression.Variable(PathBuilderHelper.GetMemberType(property)); m_variables.Add(variable); m_block.Add(variable); m_block.Add(Expression.Assign(variable, cur)); cur = variable; return(cur); }
Expression ForArray(Expression cur, Type arrayType, ParameterExpression arrayIndexesParam, int arrayIndexNum) { var getIndex = PathBuilderHelper.GetIndexExpression(arrayIndexesParam, arrayIndexNum, arrayType); cur = Expression.Convert(cur, arrayType); cur = Expression.MakeIndex(cur, arrayType.GetProperty("Item"), new[] { getIndex }); var variable = Expression.Variable(cur.Type); m_variables.Add(variable); m_block.Add(variable); m_block.Add(Expression.Assign(variable, cur)); cur = variable; return(cur); }
private Expression ForArray(Expression cur, Type tArr, ParameterExpression indexPar, int indexNum) { var indexLeng = Expression.PropertyOrField(indexPar, nameof(Array.Length)); Expression keys; if (tArr.Name == "IDictionary`2") { keys = Expression.PropertyOrField(cur, "Keys"); } else { var countKeys = Expression.PropertyOrField(Expression.Convert(cur, typeof(System.Collections.ICollection)), nameof(System.Collections.ICollection.Count)); keys = Expression.Call(s_rangeEnum, Expression.Constant(0), countKeys); } keys = Expression.Call(s_castKeys, keys); keys = Expression.Call(s_toArrayKeys, keys); m_block.Add(Expression.IfThen( Expression.LessThanOrEqual(indexLeng, Expression.Constant(indexNum)), Expression.Return(m_returnLabel, keys))); var getIndex = PathBuilderHelper.GetIndexExpression(indexPar, indexNum, tArr); cur = Expression.MakeIndex(cur, tArr.GetProperty("Item"), new[] { getIndex }); var arrVariable = Expression.Variable(cur.Type); m_block.Add(Expression.Assign(arrVariable, cur)); m_variables.Add(arrVariable); m_block.Add(arrVariable); cur = arrVariable; return(cur); }
public static Expression GetFunctionExpression(ParameterExpression sourcePar, ParameterExpression indexesPar, List <PathItem> pathItems) { int indexNum = 0; Expression cur = sourcePar; foreach (var t in pathItems) { if (t.Property != null) { cur = t.Property.ValueFromExpression(cur); } else if (t.Array != null) { Expression getIndex = PathBuilderHelper.GetIndexExpression(indexesPar, indexNum, t.Array); cur = Expression.Convert(cur, t.Array); cur = Expression.MakeIndex(cur, t.Array.GetProperty("Item"), new[] { getIndex }); indexNum++; } } return(cur); }