System.Linq.Expressions.Error.AllCaseBodiesMustHaveSameType C# (CSharp) Method

AllCaseBodiesMustHaveSameType() static private method

ArgumentException with message like "All case bodies and the default body must have the same type."
static private AllCaseBodiesMustHaveSameType ( string paramName ) : Exception
paramName string
return System.Exception
        internal static Exception AllCaseBodiesMustHaveSameType(string paramName)
        {
            return new ArgumentException(Strings.AllCaseBodiesMustHaveSameType, paramName);
        }
        /// <summary>

Usage Example

Beispiel #1
0
 /// <summary>
 /// 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.
 /// </summary>
 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);
         }
     }
 }
Error