System.DefaultBinder.FindMostSpecific C# (CSharp) Method

FindMostSpecific() private static method

private static FindMostSpecific ( ParameterInfo p1, int paramOrder1, Type paramArrayType1, ParameterInfo p2, int paramOrder2, Type paramArrayType2, Type types, Object args ) : int
p1 System.Reflection.ParameterInfo
paramOrder1 int
paramArrayType1 Type
p2 System.Reflection.ParameterInfo
paramOrder2 int
paramArrayType2 Type
types Type
args Object
return int
        private static int FindMostSpecific(ParameterInfo[] p1, int[] paramOrder1, Type paramArrayType1,
                                            ParameterInfo[] p2, int[] paramOrder2, Type paramArrayType2,
                                            Type[] types, Object[] args)
        {
            // A method using params is always less specific than one not using params
            if (paramArrayType1 != null && paramArrayType2 == null) return 2;
            if (paramArrayType2 != null && paramArrayType1 == null) return 1;

            bool p1Less = false;
            bool p2Less = false;
                
            for (int i=0;i<types.Length;i++) 
            {
                if (args != null && args[i] == Type.Missing) 
                    continue;

                Type c1 = p1[paramOrder1[i]].ParameterType;
                Type c2 = p2[paramOrder2[i]].ParameterType;

                if (i == p1.Length-1 && paramOrder1[i] == p1.Length-1 && paramArrayType1 != null)
                    c1 = paramArrayType1;
                if (i == p2.Length-1 && paramOrder2[i] == p2.Length-1 && paramArrayType2 != null)
                    c2 = paramArrayType2;

                if (c1 == c2) continue;

                switch (FindMostSpecificType(c1, c2, types[i])) {
                    case 0: return 0;
                    case 1: p1Less = true; break;
                    case 2: p2Less = true; break;
                }
            }
            
            // Two way p1Less and p2Less can be equal.  All the arguments are the
            //  same they both equal false, otherwise there were things that both
            //  were the most specific type on....
            if (p1Less == p2Less) 
            {
                // it's possible that the 2 methods have same sig and  default param in which case we match the one
                // with the same number of args but only if they were exactly the same (that is p1Less and p2Lees are both false)
                if (!p1Less && p1.Length != p2.Length && args != null) 
                {
                    if (p1.Length == args.Length) 
                    {
                        return 1;
                    }
                    else if (p2.Length == args.Length) 
                    {
                        return 2;
                    }
                }

                return 0;
            }
            else
            {
                return (p1Less == true) ? 1 : 2;
            }
        }
        

Usage Example

        // Token: 0x06000D9C RID: 3484 RVA: 0x00029C68 File Offset: 0x00027E68
        private static int FindMostSpecificMethod(MethodBase m1, int[] paramOrder1, Type paramArrayType1, MethodBase m2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
        {
            int num = DefaultBinder.FindMostSpecific(m1.GetParametersNoCopy(), paramOrder1, paramArrayType1, m2.GetParametersNoCopy(), paramOrder2, paramArrayType2, types, args);

            if (num != 0)
            {
                return(num);
            }
            if (!DefaultBinder.CompareMethodSigAndName(m1, m2))
            {
                return(0);
            }
            int hierarchyDepth  = DefaultBinder.GetHierarchyDepth(m1.DeclaringType);
            int hierarchyDepth2 = DefaultBinder.GetHierarchyDepth(m2.DeclaringType);

            if (hierarchyDepth == hierarchyDepth2)
            {
                return(0);
            }
            if (hierarchyDepth < hierarchyDepth2)
            {
                return(2);
            }
            return(1);
        }
All Usage Examples Of System.DefaultBinder::FindMostSpecific