internal static MethodBase GetCallTarget(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (TargetProcedure.IsMethod)
     {
         return TargetProcedure.AsMethod();
     }
     if (TargetProcedure.IsProperty)
     {
         return MatchesPropertyRequirements(TargetProcedure, Flags);
     }
     return null;
 }
 internal static bool InferTypeArgumentsFromArgument(Symbols.Method TargetProcedure, object Argument, ParameterInfo Parameter, bool IsExpandedParamArray, List<string> Errors)
 {
     if (Argument == null)
     {
         return true;
     }
     Type parameterType = Parameter.ParameterType;
     if (parameterType.IsByRef || IsExpandedParamArray)
     {
         parameterType = Symbols.GetElementType(parameterType);
     }
     if (InferTypeArgumentsFromArgument(GetArgumentTypeInContextOfParameterType(Argument, parameterType), parameterType, TargetProcedure.TypeArguments, TargetProcedure.AsMethod(), true))
     {
         return true;
     }
     if (Errors != null)
     {
         ReportError(Errors, "TypeInferenceFails1", Parameter.Name);
     }
     return false;
 }
 private static void CompareGenericityBasedOnMethodGenericParams(ParameterInfo LeftParameter, ParameterInfo RawLeftParameter, Symbols.Method LeftMember, bool ExpandLeftParamArray, ParameterInfo RightParameter, ParameterInfo RawRightParameter, Symbols.Method RightMember, bool ExpandRightParamArray, ref bool LeftIsLessGeneric, ref bool RightIsLessGeneric, ref bool SignatureMismatch)
 {
     if (LeftMember.IsMethod && RightMember.IsMethod)
     {
         Type parameterType = LeftParameter.ParameterType;
         Type type = RightParameter.ParameterType;
         Type elementType = RawLeftParameter.ParameterType;
         Type type3 = RawRightParameter.ParameterType;
         if (parameterType.IsByRef)
         {
             parameterType = Symbols.GetElementType(parameterType);
             elementType = Symbols.GetElementType(elementType);
         }
         if (type.IsByRef)
         {
             type = Symbols.GetElementType(type);
             type3 = Symbols.GetElementType(type3);
         }
         if (ExpandLeftParamArray && Symbols.IsParamArray(LeftParameter))
         {
             parameterType = Symbols.GetElementType(parameterType);
             elementType = Symbols.GetElementType(elementType);
         }
         if (ExpandRightParamArray && Symbols.IsParamArray(RightParameter))
         {
             type = Symbols.GetElementType(type);
             type3 = Symbols.GetElementType(type3);
         }
         if ((parameterType != type) && !Symbols.IsEquivalentType(parameterType, type))
         {
             SignatureMismatch = true;
         }
         else
         {
             MethodBase method = LeftMember.AsMethod();
             MethodBase genericMethodDefinition = RightMember.AsMethod();
             if (Symbols.IsGeneric(method))
             {
                 method = ((MethodInfo) method).GetGenericMethodDefinition();
             }
             if (Symbols.IsGeneric(genericMethodDefinition))
             {
                 genericMethodDefinition = ((MethodInfo) genericMethodDefinition).GetGenericMethodDefinition();
             }
             if (Symbols.RefersToGenericParameter(elementType, method))
             {
                 if (!Symbols.RefersToGenericParameter(type3, genericMethodDefinition))
                 {
                     RightIsLessGeneric = true;
                 }
             }
             else if (Symbols.RefersToGenericParameter(type3, genericMethodDefinition) && !Symbols.RefersToGenericParameter(elementType, method))
             {
                 LeftIsLessGeneric = true;
             }
         }
     }
 }
 internal static bool CanMatchArguments(Symbols.Method TargetProcedure, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool RejectNarrowingConversions, List<string> Errors)
 {
     bool flag2 = Errors != null;
     TargetProcedure.ArgumentsValidated = true;
     if (TargetProcedure.IsMethod && Symbols.IsRawGeneric(TargetProcedure.AsMethod()))
     {
         if (TypeArguments.Length == 0)
         {
             TypeArguments = new Type[(TargetProcedure.TypeParameters.Length - 1) + 1];
             TargetProcedure.TypeArguments = TypeArguments;
             if (!InferTypeArguments(TargetProcedure, Arguments, ArgumentNames, TypeArguments, Errors))
             {
                 return false;
             }
         }
         else
         {
             TargetProcedure.TypeArguments = TypeArguments;
         }
         if (!InstantiateGenericMethod(TargetProcedure, TypeArguments, Errors))
         {
             return false;
         }
     }
     ParameterInfo[] parameters = TargetProcedure.Parameters;
     int length = ArgumentNames.Length;
     int index = 0;
     while (length < Arguments.Length)
     {
         if (index == TargetProcedure.ParamArrayIndex)
         {
             break;
         }
         if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], false, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
         {
             return false;
         }
         length++;
         index++;
     }
     if (TargetProcedure.HasParamArray)
     {
         if (!TargetProcedure.ParamArrayExpanded)
         {
             if ((Arguments.Length - length) != 1)
             {
                 return false;
             }
             if (!CanPassToParamArray(TargetProcedure, Arguments[length], parameters[index]))
             {
                 if (flag2)
                 {
                     ReportError(Errors, "ArgumentMismatch3", parameters[index].Name, GetArgumentTypeInContextOfParameterType(Arguments[length], parameters[index].ParameterType), parameters[index].ParameterType);
                 }
                 return false;
             }
         }
         else if ((length != (Arguments.Length - 1)) || (Arguments[length] != null))
         {
             while (length < Arguments.Length)
             {
                 if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], true, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
                 {
                     return false;
                 }
                 length++;
             }
         }
         else
         {
             return false;
         }
         index++;
     }
     bool[] flagArray = null;
     if ((ArgumentNames.Length > 0) || (index < parameters.Length))
     {
         flagArray = CreateMatchTable(parameters.Length, index - 1);
     }
     if (ArgumentNames.Length > 0)
     {
         int[] numArray = new int[(ArgumentNames.Length - 1) + 1];
         for (length = 0; length < ArgumentNames.Length; length++)
         {
             if (!FindParameterByName(parameters, ArgumentNames[length], ref index))
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedParamNotFound2", ArgumentNames[length], TargetProcedure);
             }
             else if (index == TargetProcedure.ParamArrayIndex)
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedParamArrayArgument1", ArgumentNames[length]);
             }
             else if (flagArray[index])
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedArgUsedTwice2", ArgumentNames[length], TargetProcedure);
             }
             else
             {
                 if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], false, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
                 {
                     return false;
                 }
                 flagArray[index] = true;
                 numArray[length] = index;
             }
         }
         TargetProcedure.NamedArgumentMapping = numArray;
     }
     if (flagArray != null)
     {
         int num4 = flagArray.Length - 1;
         for (int i = 0; i <= num4; i++)
         {
             if (!flagArray[i] && !parameters[i].IsOptional)
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "OmittedArgument1", parameters[i].Name);
             }
         }
     }
     if ((Errors != null) && (Errors.Count > 0))
     {
         return false;
     }
     return true;
 }
        private static Symbols.Method MoreSpecificProcedure(Symbols.Method Left, Symbols.Method Right, object[] Arguments, string[] ArgumentNames, ComparisonType CompareGenericity, ref bool BothLose = false, bool ContinueWhenBothLose = false)
        {
            int num;
            MethodBase base2;
            MethodBase base3;
            BothLose = false;
            bool leftWins = false;
            bool rightWins = false;
            if (Left.IsMethod)
            {
                base2 = Left.AsMethod();
            }
            else
            {
                base2 = null;
            }
            if (Right.IsMethod)
            {
                base3 = Right.AsMethod();
            }
            else
            {
                base3 = null;
            }
            int index = 0;
            int num3 = 0;
            for (num = ArgumentNames.Length; num < Arguments.Length; num++)
            {
                Type argumentType = GetArgumentType(Arguments[num]);
                switch (CompareGenericity)
                {
                    case ComparisonType.ParameterSpecificty:
                        CompareParameterSpecificity(argumentType, Left.Parameters[index], base2, Left.ParamArrayExpanded, Right.Parameters[num3], base3, Right.ParamArrayExpanded, ref leftWins, ref rightWins, ref BothLose);
                        break;

                    case ComparisonType.GenericSpecificityBasedOnMethodGenericParams:
                        CompareGenericityBasedOnMethodGenericParams(Left.Parameters[index], Left.RawParameters[index], Left, Left.ParamArrayExpanded, Right.Parameters[num3], Right.RawParameters[num3], Right, Right.ParamArrayExpanded, ref leftWins, ref rightWins, ref BothLose);
                        break;

                    case ComparisonType.GenericSpecificityBasedOnTypeGenericParams:
                        CompareGenericityBasedOnTypeGenericParams(Left.Parameters[index], Left.RawParametersFromType[index], Left, Left.ParamArrayExpanded, Right.Parameters[num3], Right.RawParametersFromType[num3], Right, Right.ParamArrayExpanded, ref leftWins, ref rightWins, ref BothLose);
                        break;
                }
                if ((BothLose && !ContinueWhenBothLose) || (leftWins && rightWins))
                {
                    return null;
                }
                if (index != Left.ParamArrayIndex)
                {
                    index++;
                }
                if (num3 != Right.ParamArrayIndex)
                {
                    num3++;
                }
            }
            for (num = 0; num < ArgumentNames.Length; num++)
            {
                bool flag3 = FindParameterByName(Left.Parameters, ArgumentNames[num], ref index);
                bool flag4 = FindParameterByName(Right.Parameters, ArgumentNames[num], ref num3);
                if (!flag3 || !flag4)
                {
                    throw new InternalErrorException();
                }
                Type type2 = GetArgumentType(Arguments[num]);
                switch (CompareGenericity)
                {
                    case ComparisonType.ParameterSpecificty:
                        CompareParameterSpecificity(type2, Left.Parameters[index], base2, true, Right.Parameters[num3], base3, true, ref leftWins, ref rightWins, ref BothLose);
                        break;

                    case ComparisonType.GenericSpecificityBasedOnMethodGenericParams:
                        CompareGenericityBasedOnMethodGenericParams(Left.Parameters[index], Left.RawParameters[index], Left, true, Right.Parameters[num3], Right.RawParameters[num3], Right, true, ref leftWins, ref rightWins, ref BothLose);
                        break;

                    case ComparisonType.GenericSpecificityBasedOnTypeGenericParams:
                        CompareGenericityBasedOnTypeGenericParams(Left.Parameters[index], Left.RawParameters[index], Left, true, Right.Parameters[num3], Right.RawParameters[num3], Right, true, ref leftWins, ref rightWins, ref BothLose);
                        break;
                }
                if ((BothLose && !ContinueWhenBothLose) || (leftWins && rightWins))
                {
                    return null;
                }
            }
            if (leftWins)
            {
                return Left;
            }
            if (rightWins)
            {
                return Right;
            }
            return null;
        }