private static MethodBuilder EmitTupleGetHashCode(TupleType tupleType, TypeBuilder typeBuilder, Dictionary<Name, FieldInfo> fieldsByID)
{
var getHashCodeMethod = typeBuilder.DefineMethod("GetHashCode", MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot, CallingConventions.HasThis, typeof(Int32), new System.Type[] { });
var il = getHashCodeMethod.GetILGenerator();
// result = 83
il.Emit(OpCodes.Ldc_I4, 83);
foreach (var keyItem in tupleType.GetKeyAttributes())
{
var field = fieldsByID[keyItem];
// result ^= this.<field>.GetHashCode();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldflda, field);
il.Emit(OpCodes.Constrained, field.FieldType);
il.EmitCall(OpCodes.Callvirt, ReflectionUtility.ObjectGetHashCode, null);
il.Emit(OpCodes.Xor);
}
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(getHashCodeMethod, ReflectionUtility.ObjectGetHashCode);
return getHashCodeMethod;
}