/// <summary> /// 执行解析。 /// </summary> private void AnalysisExpres() { while (true) { if (_theQueue.Count > 0) { var bindWithStorey = _theQueue.Dequeue(); foreach (var memBind in bindWithStorey.TheExpression.Bindings) { //只取成员赋值表达式。忽略其余。 if (memBind is MemberAssignment) { var memAss = memBind as MemberAssignment; var thisStorey = bindWithStorey.Storey + "." + memAss.Member.Name; //如果成员赋值表达式的子表达式是一个成员创建表达式。则记录其层次,并按层次解析。 //如果不是则可能是常量值、变量值、各种运算符表达式或调用方法的返回值,则直接计算其结果。 if (memAss.Expression.NodeType == ExpressionType.MemberInit) { var membInitExp = memAss.Expression as MemberInitExpression; var aStorey = new MemberBindingWithStorey() { Storey = thisStorey, TheExpression = membInitExp }; _theQueue.Enqueue(aStorey); } else { var thisMebbVal = new MemberInform(); thisStorey = thisStorey.Trim('.'); thisMebbVal.MemberRoute = thisStorey; thisMebbVal.ValueType = memAss.Expression.Type; var value = TranslateToDirectValue(memAss); thisMebbVal.Value = value; _propRoutList.Add(thisMebbVal); } } } } else { break; } } }
/// <summary> /// 开始解析。 /// </summary> /// <param name="memInitExpr">要解析的表达示。</param> /// <returns>成员信息列表。</returns> public IEnumerable <MemberInform> Analysiser(MemberInitExpression memInitExpr) { var bindWithStorey = new MemberBindingWithStorey() { Storey = "", TheExpression = memInitExpr }; _theQueue.Enqueue(bindWithStorey); AnalysisExpres(); return(_propRoutList); }