Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Switch() [5/6]

static SwitchExpression System.Linq.Expressions.Expression< TDelegate >.Switch ( Type? type,
Expression< TDelegate > switchValue,
Expression< TDelegate >? defaultBody,
MethodInfo? comparison,
IEnumerable< SwitchCase >? cases )
inlinestaticinherited

Definition at line 4752 of file Expression.cs.

4753 {
4755 if (switchValue.Type == typeof(void))
4756 {
4757 throw Error.ArgumentCannotBeOfTypeVoid("switchValue");
4758 }
4760 ContractUtils.RequiresNotNullItems(readOnlyCollection, "cases");
4762 bool customType = type != null;
4763 if (comparison != null)
4764 {
4765 ValidateMethodInfo(comparison, "comparison");
4766 ParameterInfo[] parametersCached = comparison.GetParametersCached();
4767 if (parametersCached.Length != 2)
4768 {
4769 throw Error.IncorrectNumberOfMethodCallArguments(comparison, "comparison");
4770 }
4772 bool flag = false;
4774 {
4775 flag = ParameterIsAssignable(parameterInfo, switchValue.Type.GetNonNullableType());
4776 if (!flag)
4777 {
4778 throw Error.SwitchValueTypeDoesNotMatchComparisonMethodParameter(switchValue.Type, parameterInfo.ParameterType);
4779 }
4780 }
4783 {
4786 int i = 0;
4787 for (int count = item.TestValues.Count; i < count; i++)
4788 {
4789 Type type3 = item.TestValues[i].Type;
4790 if (flag)
4791 {
4792 if (!type3.IsNullableType())
4793 {
4794 throw Error.TestValueTypeDoesNotMatchComparisonMethodParameter(type3, parameterInfo2.ParameterType);
4795 }
4796 type3 = type3.GetNonNullableType();
4797 }
4799 {
4800 throw Error.TestValueTypeDoesNotMatchComparisonMethodParameter(type3, parameterInfo2.ParameterType);
4801 }
4802 }
4803 }
4804 if (comparison.ReturnType != typeof(bool))
4805 {
4806 throw Error.EqualityMustReturnBoolean(comparison, "comparison");
4807 }
4808 }
4809 else if (readOnlyCollection.Count != 0)
4810 {
4811 Expression expression = readOnlyCollection[0].TestValues[0];
4813 {
4816 int j = 0;
4817 for (int count2 = item2.TestValues.Count; j < count2; j++)
4818 {
4819 if (!TypeUtils.AreEquivalent(expression.Type, item2.TestValues[j].Type))
4820 {
4821 throw Error.AllTestValuesMustHaveSameType("cases");
4822 }
4823 }
4824 }
4827 }
4828 if (defaultBody == null)
4829 {
4830 if (type2 != typeof(void))
4831 {
4832 throw Error.DefaultBodyMustBeSupplied("defaultBody");
4833 }
4834 }
4835 else
4836 {
4838 }
4839 return new SwitchExpression(type2, switchValue, defaultBody, comparison, readOnlyCollection);
4840 }
static void RequiresNotNull(object value, string paramName)
static void RequiresCanRead(Expression expression, string paramName)
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
static SwitchCase SwitchCase(Expression body, params Expression[] testValues)
static void ValidateMethodInfo(MethodInfo method, string paramName)
static void ValidateSwitchCaseType(Expression @case, bool customType, Type resultType, string parameterName)
static bool ParameterIsAssignable(ParameterInfo pi, Type argType)

References System.Linq.Expressions.Error.AllTestValuesMustHaveSameType(), System.Dynamic.Utils.TypeUtils.AreEquivalent(), System.Linq.Expressions.Error.ArgumentCannotBeOfTypeVoid(), System.Linq.Expressions.LambdaExpression.Body, System.comparison, System.Linq.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Linq.Expressions.Error.DefaultBodyMustBeSupplied(), System.Linq.Expressions.Equal, System.Linq.Expressions.Error.EqualityMustReturnBoolean(), System.Linq.Expressions.Error.IncorrectNumberOfMethodCallArguments(), System.item, System.Linq.Expressions.Expression< TDelegate >.ParameterIsAssignable(), System.Dynamic.Utils.ExpressionUtils.RequiresCanRead(), System.Dynamic.Utils.ContractUtils.RequiresNotNull(), System.Linq.Expressions.Error.SwitchValueTypeDoesNotMatchComparisonMethodParameter(), System.Linq.Expressions.Error.TestValueTypeDoesNotMatchComparisonMethodParameter(), System.Linq.Expressions.Expression< TDelegate >.Type, System.type, System.Linq.Expressions.Expression< TDelegate >.ValidateMethodInfo(), and System.Linq.Expressions.Expression< TDelegate >.ValidateSwitchCaseType().