// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.CodeAnalysis.Shared.Extensions { internal static partial class ObjectExtensions { #region TypeSwitch on Func public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func defaultFunc = null) where TDerivedType1 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func matchFunc34, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType where TDerivedType34 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (obj is TDerivedType34) { return matchFunc34((TDerivedType34)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func matchFunc34, Func matchFunc35, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType where TDerivedType34 : TBaseType where TDerivedType35 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (obj is TDerivedType34) { return matchFunc34((TDerivedType34)obj); } else if (obj is TDerivedType35) { return matchFunc35((TDerivedType35)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func matchFunc34, Func matchFunc35, Func matchFunc36, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType where TDerivedType34 : TBaseType where TDerivedType35 : TBaseType where TDerivedType36 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (obj is TDerivedType34) { return matchFunc34((TDerivedType34)obj); } else if (obj is TDerivedType35) { return matchFunc35((TDerivedType35)obj); } else if (obj is TDerivedType36) { return matchFunc36((TDerivedType36)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func matchFunc34, Func matchFunc35, Func matchFunc36, Func matchFunc37, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType where TDerivedType34 : TBaseType where TDerivedType35 : TBaseType where TDerivedType36 : TBaseType where TDerivedType37 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (obj is TDerivedType34) { return matchFunc34((TDerivedType34)obj); } else if (obj is TDerivedType35) { return matchFunc35((TDerivedType35)obj); } else if (obj is TDerivedType36) { return matchFunc36((TDerivedType36)obj); } else if (obj is TDerivedType37) { return matchFunc37((TDerivedType37)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } public static TResult TypeSwitch(this TBaseType obj, Func matchFunc1, Func matchFunc2, Func matchFunc3, Func matchFunc4, Func matchFunc5, Func matchFunc6, Func matchFunc7, Func matchFunc8, Func matchFunc9, Func matchFunc10, Func matchFunc11, Func matchFunc12, Func matchFunc13, Func matchFunc14, Func matchFunc15, Func matchFunc16, Func matchFunc17, Func matchFunc18, Func matchFunc19, Func matchFunc20, Func matchFunc21, Func matchFunc22, Func matchFunc23, Func matchFunc24, Func matchFunc25, Func matchFunc26, Func matchFunc27, Func matchFunc28, Func matchFunc29, Func matchFunc30, Func matchFunc31, Func matchFunc32, Func matchFunc33, Func matchFunc34, Func matchFunc35, Func matchFunc36, Func matchFunc37, Func matchFunc38, Func defaultFunc = null) where TDerivedType1 : TBaseType where TDerivedType2 : TBaseType where TDerivedType3 : TBaseType where TDerivedType4 : TBaseType where TDerivedType5 : TBaseType where TDerivedType6 : TBaseType where TDerivedType7 : TBaseType where TDerivedType8 : TBaseType where TDerivedType9 : TBaseType where TDerivedType10 : TBaseType where TDerivedType11 : TBaseType where TDerivedType12 : TBaseType where TDerivedType13 : TBaseType where TDerivedType14 : TBaseType where TDerivedType15 : TBaseType where TDerivedType16 : TBaseType where TDerivedType17 : TBaseType where TDerivedType18 : TBaseType where TDerivedType19 : TBaseType where TDerivedType20 : TBaseType where TDerivedType21 : TBaseType where TDerivedType22 : TBaseType where TDerivedType23 : TBaseType where TDerivedType24 : TBaseType where TDerivedType25 : TBaseType where TDerivedType26 : TBaseType where TDerivedType27 : TBaseType where TDerivedType28 : TBaseType where TDerivedType29 : TBaseType where TDerivedType30 : TBaseType where TDerivedType31 : TBaseType where TDerivedType32 : TBaseType where TDerivedType33 : TBaseType where TDerivedType34 : TBaseType where TDerivedType35 : TBaseType where TDerivedType36 : TBaseType where TDerivedType37 : TBaseType where TDerivedType38 : TBaseType { if (obj is TDerivedType1) { return matchFunc1((TDerivedType1)obj); } else if (obj is TDerivedType2) { return matchFunc2((TDerivedType2)obj); } else if (obj is TDerivedType3) { return matchFunc3((TDerivedType3)obj); } else if (obj is TDerivedType4) { return matchFunc4((TDerivedType4)obj); } else if (obj is TDerivedType5) { return matchFunc5((TDerivedType5)obj); } else if (obj is TDerivedType6) { return matchFunc6((TDerivedType6)obj); } else if (obj is TDerivedType7) { return matchFunc7((TDerivedType7)obj); } else if (obj is TDerivedType8) { return matchFunc8((TDerivedType8)obj); } else if (obj is TDerivedType9) { return matchFunc9((TDerivedType9)obj); } else if (obj is TDerivedType10) { return matchFunc10((TDerivedType10)obj); } else if (obj is TDerivedType11) { return matchFunc11((TDerivedType11)obj); } else if (obj is TDerivedType12) { return matchFunc12((TDerivedType12)obj); } else if (obj is TDerivedType13) { return matchFunc13((TDerivedType13)obj); } else if (obj is TDerivedType14) { return matchFunc14((TDerivedType14)obj); } else if (obj is TDerivedType15) { return matchFunc15((TDerivedType15)obj); } else if (obj is TDerivedType16) { return matchFunc16((TDerivedType16)obj); } else if (obj is TDerivedType17) { return matchFunc17((TDerivedType17)obj); } else if (obj is TDerivedType18) { return matchFunc18((TDerivedType18)obj); } else if (obj is TDerivedType19) { return matchFunc19((TDerivedType19)obj); } else if (obj is TDerivedType20) { return matchFunc20((TDerivedType20)obj); } else if (obj is TDerivedType21) { return matchFunc21((TDerivedType21)obj); } else if (obj is TDerivedType22) { return matchFunc22((TDerivedType22)obj); } else if (obj is TDerivedType23) { return matchFunc23((TDerivedType23)obj); } else if (obj is TDerivedType24) { return matchFunc24((TDerivedType24)obj); } else if (obj is TDerivedType25) { return matchFunc25((TDerivedType25)obj); } else if (obj is TDerivedType26) { return matchFunc26((TDerivedType26)obj); } else if (obj is TDerivedType27) { return matchFunc27((TDerivedType27)obj); } else if (obj is TDerivedType28) { return matchFunc28((TDerivedType28)obj); } else if (obj is TDerivedType29) { return matchFunc29((TDerivedType29)obj); } else if (obj is TDerivedType30) { return matchFunc30((TDerivedType30)obj); } else if (obj is TDerivedType31) { return matchFunc31((TDerivedType31)obj); } else if (obj is TDerivedType32) { return matchFunc32((TDerivedType32)obj); } else if (obj is TDerivedType33) { return matchFunc33((TDerivedType33)obj); } else if (obj is TDerivedType34) { return matchFunc34((TDerivedType34)obj); } else if (obj is TDerivedType35) { return matchFunc35((TDerivedType35)obj); } else if (obj is TDerivedType36) { return matchFunc36((TDerivedType36)obj); } else if (obj is TDerivedType37) { return matchFunc37((TDerivedType37)obj); } else if (obj is TDerivedType38) { return matchFunc38((TDerivedType38)obj); } else if (defaultFunc != null) { return defaultFunc(obj); } else { return default(TResult); } } #endregion } }