<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;

namespace Harmony
{
	public class HarmonyMethod
	{
		public MethodInfo method; // need to be called 'method'

		public Type declaringType;
		public string methodName;
		public MethodType methodType;
		public Type[] argumentTypes;
		public int prioritiy = -1;
		public string[] before;
		public string[] after;

		public HarmonyMethod()
		{
		}

		void ImportMethod(MethodInfo theMethod)
		{
			method = theMethod;
			if (method != null)
			{
				var infos = method.GetHarmonyMethods();
				if (infos != null)
					Merge(infos).CopyTo(this);
			}
		}

		public HarmonyMethod(MethodInfo method)
		{
			ImportMethod(method);
		}

		public HarmonyMethod(Type type, string name, Type[] parameters = null)
		{
			var method = AccessTools.Method(type, name, parameters);
			ImportMethod(method);
		}

		public static List<string> HarmonyFields()
		{
			return AccessTools
				.GetFieldNames(typeof(HarmonyMethod))
				.Where(s => s != "method")
				.ToList();
		}

		public static HarmonyMethod Merge(List<HarmonyMethod> attributes)
		{
			var result = new HarmonyMethod();
			if (attributes == null) return result;
			var resultTrv = Traverse.Create(result);
			attributes.ForEach(attribute =>
			{
				var trv = Traverse.Create(attribute);
				HarmonyFields().ForEach(f =>
				{
					var val = trv.Field(f).GetValue();
					if (val != null)
						resultTrv.Field(f).SetValue(val);
				});
			});
			return result;
		}
	}

	public static class HarmonyMethodExtensions
	{
		public static void CopyTo(this HarmonyMethod from, HarmonyMethod to)
		{
			if (to == null) return;
			var fromTrv = Traverse.Create(from);
			var toTrv = Traverse.Create(to);
			HarmonyMethod.HarmonyFields().ForEach(f =>
			{
				var val = fromTrv.Field(f).GetValue();
				if (val != null) toTrv.Field(f).SetValue(val);
			});
		}

		public static HarmonyMethod Clone(this HarmonyMethod original)
		{
			var result = new HarmonyMethod();
			original.CopyTo(result);
			return result;
		}

		public static HarmonyMethod Merge(this HarmonyMethod master, HarmonyMethod detail)
		{
			if (detail == null) return master;
			var result = new HarmonyMethod();
			var resultTrv = Traverse.Create(result);
			var masterTrv = Traverse.Create(master);
			var detailTrv = Traverse.Create(detail);
			HarmonyMethod.HarmonyFields().ForEach(f =>
			{
				var baseValue = masterTrv.Field(f).GetValue();
				var detailValue = detailTrv.Field(f).GetValue();
				resultTrv.Field(f).SetValue(detailValue ?? baseValue);
			});
			return result;
		}

		public static List<HarmonyMethod> GetHarmonyMethods(this Type type)
		{
			return type.GetCustomAttributes(true)
						.Where(attr => attr is HarmonyAttribute)
						.Cast<HarmonyAttribute>()
						.Select(attr => attr.info)
						.ToList();
		}

		public static List<HarmonyMethod> GetHarmonyMethods(this MethodBase method)
		{
			if (method is DynamicMethod) return new List<HarmonyMethod>();
			return method.GetCustomAttributes(true)
						.Where(attr => attr is HarmonyAttribute)
						.Cast<HarmonyAttribute>()
						.Select(attr => attr.info)
						.ToList();
		}
	}
}<commit_msg>Make methodType optional so merging works; Add a ToString method<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;

namespace Harmony
{
	public class HarmonyMethod
	{
		public MethodInfo method; // need to be called 'method'

		public Type declaringType;
		public string methodName;
		public MethodType? methodType;
		public Type[] argumentTypes;
		public int prioritiy = -1;
		public string[] before;
		public string[] after;

		public HarmonyMethod()
		{
		}

		void ImportMethod(MethodInfo theMethod)
		{
			method = theMethod;
			if (method != null)
			{
				var infos = method.GetHarmonyMethods();
				if (infos != null)
					Merge(infos).CopyTo(this);
			}
		}

		public HarmonyMethod(MethodInfo method)
		{
			ImportMethod(method);
		}

		public HarmonyMethod(Type type, string name, Type[] parameters = null)
		{
			var method = AccessTools.Method(type, name, parameters);
			ImportMethod(method);
		}

		public static List<string> HarmonyFields()
		{
			return AccessTools
				.GetFieldNames(typeof(HarmonyMethod))
				.Where(s => s != "method")
				.ToList();
		}

		public static HarmonyMethod Merge(List<HarmonyMethod> attributes)
		{
			var result = new HarmonyMethod();
			if (attributes == null) return result;
			var resultTrv = Traverse.Create(result);
			attributes.ForEach(attribute =>
			{
				var trv = Traverse.Create(attribute);
				HarmonyFields().ForEach(f =>
				{
					var val = trv.Field(f).GetValue();
					if (val != null)
						resultTrv.Field(f).SetValue(val);
				});
			});
			return result;
		}

		public override string ToString()
		{
			var result = "HarmonyMethod[";
			var trv = Traverse.Create(this);
			HarmonyFields().ForEach(f =>
			{
				result += f + '=' + trv.Field(f).GetValue();
			});
			return result + "]";
		}
	}

	public static class HarmonyMethodExtensions
	{
		public static void CopyTo(this HarmonyMethod from, HarmonyMethod to)
		{
			if (to == null) return;
			var fromTrv = Traverse.Create(from);
			var toTrv = Traverse.Create(to);
			HarmonyMethod.HarmonyFields().ForEach(f =>
			{
				var val = fromTrv.Field(f).GetValue();
				if (val != null) toTrv.Field(f).SetValue(val);
			});
		}

		public static HarmonyMethod Clone(this HarmonyMethod original)
		{
			var result = new HarmonyMethod();
			original.CopyTo(result);
			return result;
		}

		public static HarmonyMethod Merge(this HarmonyMethod master, HarmonyMethod detail)
		{
			if (detail == null) return master;
			var result = new HarmonyMethod();
			var resultTrv = Traverse.Create(result);
			var masterTrv = Traverse.Create(master);
			var detailTrv = Traverse.Create(detail);
			HarmonyMethod.HarmonyFields().ForEach(f =>
			{
				var baseValue = masterTrv.Field(f).GetValue();
				var detailValue = detailTrv.Field(f).GetValue();
				resultTrv.Field(f).SetValue(detailValue ?? baseValue);
			});
			return result;
		}

		public static List<HarmonyMethod> GetHarmonyMethods(this Type type)
		{
			return type.GetCustomAttributes(true)
						.Where(attr => attr is HarmonyAttribute)
						.Cast<HarmonyAttribute>()
						.Select(attr => attr.info)
						.ToList();
		}

		public static List<HarmonyMethod> GetHarmonyMethods(this MethodBase method)
		{
			if (method is DynamicMethod) return new List<HarmonyMethod>();
			return method.GetCustomAttributes(true)
						.Where(attr => attr is HarmonyAttribute)
						.Cast<HarmonyAttribute>()
						.Select(attr => attr.info)
						.ToList();
		}
	}
}
{'fraction_non_alphanumeric': 0.11898395721925134, 'fraction_numerical': 0.00029708853238265005, 'mean_word_length': 3.5431848852901484, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1170730', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2144, 'n_words': 507}