Esempio n. 1
0
        // CONSIDER: Should we introduce CSharpConversion and use that as the factory?

        /// <summary>
        /// Creates a simple conversion using the specified <paramref name="conversion"/> lambda.
        /// </summary>
        /// <param name="conversion">The lambda expression representing the conversion.</param>
        /// <returns>A <see cref="SimpleConversion"/ object.</returns>
        public static SimpleConversion Convert(LambdaExpression conversion)
        {
            RequiresNotNull(conversion, nameof(conversion));

            if (conversion.Parameters.Count != 1)
            {
                throw Error.ConversionShouldHaveOneParameter();
            }

            if (conversion.ReturnType == typeof(void))
            {
                throw Error.ConversionCannotReturnVoid();
            }

            return(new SimpleConversion(conversion));
        }