Rhino.NativeJavaMethod.PreferSignature C# (CSharp) Method

PreferSignature() private static method

Determine which of two signatures is the closer fit.
Determine which of two signatures is the closer fit. Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG, PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.
private static PreferSignature ( object args, Type sig1, bool vararg1, Type sig2, bool vararg2 ) : int
args object
sig1 System.Type
vararg1 bool
sig2 System.Type
vararg2 bool
return int
		private static int PreferSignature(object[] args, Type[] sig1, bool vararg1, Type[] sig2, bool vararg2)
		{
			int totalPreference = 0;
			for (int j = 0; j < args.Length; j++)
			{
				Type type1 = vararg1 && j >= sig1.Length ? sig1[sig1.Length - 1] : sig1[j];
				Type type2 = vararg2 && j >= sig2.Length ? sig2[sig2.Length - 1] : sig2[j];
				if (type1 == type2)
				{
					continue;
				}
				object arg = args[j];
				// Determine which of type1, type2 is easier to convert from arg.
				int rank1 = NativeJavaObject.GetConversionWeight(arg, type1);
				int rank2 = NativeJavaObject.GetConversionWeight(arg, type2);
				int preference;
				if (rank1 < rank2)
				{
					preference = PREFERENCE_FIRST_ARG;
				}
				else
				{
					if (rank1 > rank2)
					{
						preference = PREFERENCE_SECOND_ARG;
					}
					else
					{
						// Equal ranks
						if (rank1 == NativeJavaObject.CONVERSION_NONTRIVIAL)
						{
							if (type1.IsAssignableFrom(type2))
							{
								preference = PREFERENCE_SECOND_ARG;
							}
							else
							{
								if (type2.IsAssignableFrom(type1))
								{
									preference = PREFERENCE_FIRST_ARG;
								}
								else
								{
									preference = PREFERENCE_AMBIGUOUS;
								}
							}
						}
						else
						{
							preference = PREFERENCE_AMBIGUOUS;
						}
					}
				}
				totalPreference |= preference;
				if (totalPreference == PREFERENCE_AMBIGUOUS)
				{
					break;
				}
			}
			return totalPreference;
		}