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