If you're talking about the termComparator, that wasn't made generic until 3.1. The comparator in 3.0.3 can't be ported the way it is anyway because of Java's type system, but I just want to make sure you're porting 3.0.3 to keep everything in line with the rest of the .NET versions. You'll find that the 3.x version in java uses a few other additions to the main lucene library that aren't yet available in 3.0.3.
This problem should be easily solved without reflection. The comparator used basically requires that it be a KeyValuePair<TKey, TValue>, or more specifically, a KeyValuePair<string, TValue>. There are actually only 2 different types that uses that termComparator: KeyValuePair<string, ArrayIntList> and KeyValuePair<string,Info>. An exception to that is the private static sort(Dictionary<K,V>) method, but that can be solved with a static method, a type constraint (which is already implied in the java version) and some type inference (as a nicety). I had ported most of this at one point (somewhere on my home computer), and if memory serves me correctly, I think this is how I solved this problem.
You can use this if you want:
public static int Comparer<TKey, TValue>(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TValue> y)
where TKey : IComparable<TKey>
if (x.Equals(y)) return 0;
sealed class KvpComparer<T> : KvpComparer, IComparer<KeyValuePair<string, T>>
public int Compare(KeyValuePair<string, T> x, KeyValuePair<string, T> y)
return Comparer(x, y);
You can create the two instances you need for the <string,Info> and <string,ArrayIntList> types. For the Map.Entry<K,V> sort(HashMap<K,V> map method, constrain K to IComparable<K>, and then you can use it like Array.Sort(entries, KvpComparer.Compare), which is nice because it's one less object you need to create (or more) for each type passed into sort. Alternatively, since the sort method is private, and only uses those two types, you can just change the signature and pass in one of the comparers instead, removing the base class from the equation.