System.DefaultBinder.FindMostSpecificType C# (CSharp) Method

FindMostSpecificType() private static method

private static FindMostSpecificType ( Type c1, Type c2, Type t ) : int
c1 Type
c2 Type
t Type
return int
        private static int FindMostSpecificType(Type c1, Type c2, Type t)
        {
            // If the two types are exact move on...
            if (c1 == c2)
                return 0;

            if (c1 == t) 
                return 1;
            
            if (c2 == t) 
                return 2;         

            bool c1FromC2;
            bool c2FromC1;

            if (c1.IsByRef || c2.IsByRef)
            {
                if (c1.IsByRef && c2.IsByRef)
                {
                    c1 = c1.GetElementType();
                    c2 = c2.GetElementType();
                }
                else if (c1.IsByRef)
                {
                    if (c1.GetElementType() == c2)
                        return 2;

                    c1 = c1.GetElementType();
                }
                else 
                {
                    if (c2.GetElementType() == c1)
                        return 1;

                    c2 = c2.GetElementType();
                }
            }
            

            if (c1.IsPrimitive && c2.IsPrimitive) 
            {
                c1FromC2 = CanConvertPrimitive((RuntimeType)c2, (RuntimeType)c1);
                c2FromC1 = CanConvertPrimitive((RuntimeType)c1, (RuntimeType)c2);
            }
            else
            {
                c1FromC2 = c1.IsAssignableFrom(c2);
                c2FromC1 = c2.IsAssignableFrom(c1);
            }

            if (c1FromC2 == c2FromC1)
                return 0;

            if (c1FromC2)
            {
                return 2;
            }
            else
            {
                return 1;
            }
        }

Usage Example

Beispiel #1
0
        private static int FindMostSpecific(ParameterInfo[] p1, int[] paramOrder1, Type paramArrayType1, ParameterInfo[] p2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
        {
            if (paramArrayType1 != (Type)null && paramArrayType2 == (Type)null)
            {
                return(2);
            }
            if (paramArrayType2 != (Type)null && paramArrayType1 == (Type)null)
            {
                return(1);
            }
            bool flag1 = false;
            bool flag2 = false;

            for (int index = 0; index < types.Length; ++index)
            {
                if (args == null || args[index] != Type.Missing)
                {
                    Type c1 = !(paramArrayType1 != (Type)null) || paramOrder1[index] < p1.Length - 1 ? p1[paramOrder1[index]].ParameterType : paramArrayType1;
                    Type c2 = !(paramArrayType2 != (Type)null) || paramOrder2[index] < p2.Length - 1 ? p2[paramOrder2[index]].ParameterType : paramArrayType2;
                    if (!(c1 == c2))
                    {
                        switch (DefaultBinder.FindMostSpecificType(c1, c2, types[index]))
                        {
                        case 0:
                            return(0);

                        case 1:
                            flag1 = true;
                            continue;

                        case 2:
                            flag2 = true;
                            continue;

                        default:
                            continue;
                        }
                    }
                }
            }
            if (flag1 == flag2)
            {
                if (!flag1 && args != null)
                {
                    if (p1.Length > p2.Length)
                    {
                        return(1);
                    }
                    if (p2.Length > p1.Length)
                    {
                        return(2);
                    }
                }
                return(0);
            }
            return(!flag1 ? 2 : 1);
        }
All Usage Examples Of System.DefaultBinder::FindMostSpecificType