System.Linq.Expressions.Expression.ValidateSwitchCaseType C# (CSharp) Метод

ValidateSwitchCaseType() приватный статический Метод

If custom type is provided, all branches must be reference assignable to the result type. If no custom type is provided, all branches must have the same type - resultType.
private static ValidateSwitchCaseType ( Expression @case, bool customType, Type resultType, string parameterName ) : void
@case Expression
customType bool
resultType Type
parameterName string
Результат void
        private static void ValidateSwitchCaseType(Expression @case, bool customType, Type resultType, string parameterName)
        {
            if (customType)
            {
                if (resultType != typeof(void))
                {
                    if (!TypeUtils.AreReferenceAssignable(resultType, @case.Type))
                    {
                        throw Error.ArgumentTypesMustMatch(parameterName);
                    }
                }
            }
            else
            {
                if (!TypeUtils.AreEquivalent(resultType, @case.Type))
                {
                    throw Error.AllCaseBodiesMustHaveSameType(parameterName);
                }
            }
        }
    }
Expression