public static ConvertByteArrayToInt CustomInternal(ConvertByteArrayToInt conversionFunction, WrapperByteArray internalFunction) { return delegate(byte[] data) { return conversionFunction(internalFunction(data)); }; }
public static int DetermineRank(int score, Regex pattern, object hiscoreData, ConvertByteArrayToInt methodToCallOnData) { //Get all the fields into a FieldInfo array. FieldInfo[] info = hiscoreData.GetType().GetFields(); List<FieldInfo> sortedInfo = new List<FieldInfo>(); //Add all the fields sortedInfo.AddRange(info); //Remove any fields that do NOT match this pattern in adjusters. sortedInfo.RemoveAll(new NotMatching(pattern).NotMatch); //Sort by the numeric portion of the pattern in adjusters in ascending numerical order. //(i.e. Score1, Score2, ... Scoren or Name1, Name2, ... Namen) sortedInfo.Sort(new FieldInfoNameComparator(FieldInfoNameComparator.Ordering.Ascending)); int rankCounter = 0; foreach (FieldInfo fi in sortedInfo) { //If we match our pattern, check against our GetValue method to determine if we have a larger //score. if (pattern.IsMatch(fi.Name)) { if (score > methodToCallOnData((byte[])fi.GetValue(hiscoreData))) return rankCounter; } rankCounter++; } //If we don't have a larger score value, rankCounter will be equal to NumEntries. return rankCounter; }