Ancestry.QueryProcessor.Compile.ReflectionUtility.IsSimilarType C# (CSharp) Method

IsSimilarType() private static method

Determines if the two types are either identical, or are both generic parameters or generic types with generic parameters in the same locations (generic parameters match any other generic parameter, but NOT concrete types).
private static IsSimilarType ( this thisType, System type ) : bool
thisType this
type System
return bool
        private static bool IsSimilarType(this System.Type thisType, System.Type type)
        {
            // Ignore any 'ref' types
            if (thisType.IsByRef)
                thisType = thisType.GetElementType();
            if (type.IsByRef)
                type = type.GetElementType();

            // Handle array types
            if (thisType.IsArray && type.IsArray)
                return thisType.GetElementType().IsSimilarType(type.GetElementType());

            // If the types are identical, or they're both generic parameters or the special 'T' type, treat as a match
            if (thisType == type || ((thisType.IsGenericParameter || thisType == typeof(T)) && (type.IsGenericParameter || type == typeof(T))))
                return true;

            // Handle any generic arguments
            if (thisType.IsGenericType && type.IsGenericType)
            {
                System.Type[] thisArguments = thisType.GetGenericArguments();
                System.Type[] arguments = type.GetGenericArguments();
                if (thisArguments.Length == arguments.Length)
                    return !thisArguments.Where((t, i) => !t.IsSimilarType(arguments[i])).Any();
            }

            return false;
        }