/// <summary> /// Creates a deconstruction conversion using the specified <paramref name="conversions"/> to apply to the components obtained through deconstruction. /// </summary> /// <param name="deconstruct">The deconstruction lambda to invoke if the input is not a tuple type.</param> /// <param name="conversions">The conversions to apply to the tuple components.</param> /// <returns>A <see cref="DeconstructionConversion"/ object representing the deconstruction of an object.</returns> public static DeconstructionConversion Deconstruct(LambdaExpression deconstruct, IEnumerable <Conversion> conversions) { var conversionsList = conversions.ToReadOnly(); RequiresNotNullItems(conversionsList, nameof(conversions)); if (deconstruct != null) { CheckDeconstructLambda(deconstruct.Body, deconstruct.Parameters); var n = deconstruct.Parameters.Count; if (n - 1 != conversionsList.Count) { throw Error.DeconstructionParameterCountShouldMatchConversionCount(); } for (var i = 1; i < n; i++) { var parameter = deconstruct.Parameters[i]; var conversion = conversionsList[i - 1]; if (!TypeUtils.AreReferenceAssignable(conversion.InputType, parameter.Type)) { throw Error.DeconstructionParameterNotAssignableToConversion(i, parameter.Type, conversion.InputType); } } } return(new DeconstructionConversion(deconstruct, conversionsList)); }