private IEnumerable <MemberBinding> GetMemberBindingsForNewExpression(NewExpression newExpression) { for (var i = 0; i < newExpression.Members.Count; ++i) { yield return(MemberBinding.Bind(newExpression.Members[i], newExpression.Arguments[i])); } }
private IEnumerable <MemberBinding> GetMemberBindingsCreatedByExpression(Expression expression) { var memberInitExpression = expression as MemberInitExpression; if (memberInitExpression != null) { return(memberInitExpression.Bindings .Where(binding => binding is MemberAssignment) .Select(assignment => MemberBinding.Bind(assignment.Member, ((MemberAssignment)assignment).Expression))); } var newExpression = expression as NewExpression; if (newExpression != null && newExpression.Members != null) { return(GetMemberBindingsForNewExpression(newExpression)); } return(null); }