{"action":"created","issue":{"url":"https://api.github.com/repos/pardeike/Harmony/issues/156","repository_url":"https://api.github.com/repos/pardeike/Harmony","labels_url":"https://api.github.com/repos/pardeike/Harmony/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/pardeike/Harmony/issues/156/comments","events_url":"https://api.github.com/repos/pardeike/Harmony/issues/156/events","html_url":"https://github.com/pardeike/Harmony/issues/156","id":405975392,"node_id":"MDU6SXNzdWU0MDU5NzUzOTI=","number":156,"title":"Can't patch method (with overloads) in generic type","user":{"login":"alexb5dh","id":4650832,"node_id":"MDQ6VXNlcjQ2NTA4MzI=","avatar_url":"https://avatars0.githubusercontent.com/u/4650832?v=4","gravatar_id":"","url":"https://api.github.com/users/alexb5dh","html_url":"https://github.com/alexb5dh","followers_url":"https://api.github.com/users/alexb5dh/followers","following_url":"https://api.github.com/users/alexb5dh/following{/other_user}","gists_url":"https://api.github.com/users/alexb5dh/gists{/gist_id}","starred_url":"https://api.github.com/users/alexb5dh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexb5dh/subscriptions","organizations_url":"https://api.github.com/users/alexb5dh/orgs","repos_url":"https://api.github.com/users/alexb5dh/repos","events_url":"https://api.github.com/users/alexb5dh/events{/privacy}","received_events_url":"https://api.github.com/users/alexb5dh/received_events","type":"User","site_admin":false},"labels":[{"id":511525300,"node_id":"MDU6TGFiZWw1MTE1MjUzMDA=","url":"https://api.github.com/repos/pardeike/Harmony/labels/wontfix","name":"wontfix","color":"ffffff","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2019-02-02T11:39:12Z","updated_at":"2019-02-02T13:49:05Z","closed_at":"2019-02-02T13:38:51Z","author_association":"NONE","body":"Code below logs a lot of different `List<T>.Add` calls where `T` is not a `string`.\r\n```\r\n[HarmonyPatch(typeof(List<string>), new[] { typeof(string) })] // generic type\r\n[HarmonyPatch(nameof(List<string>.Add), typeof(string))] // method\r\nstatic class ListAddPatch\r\n{\r\n    public static void Prefix(List<string> __instance) => Console.WriteLine(__instance);\r\n}\r\n\r\nstatic class Program\r\n{\r\n    public static void Main() => HarmonyInstance.Create(\"patch\").PatchAll();\r\n}\r\n```\r\n\r\nRemoving `string` from `List<string>` (since it's already passed as type parameter):\r\n```\r\n[HarmonyPatch(typeof(List<>), new[] { typeof(string) })] // generic type\r\n[HarmonyPatch(nameof(List<string>.Add), typeof(string))] // method\r\n```\r\ngives\r\n```\r\nSystem.ArgumentException: No target method specified for class ConsoleTest.ListAddPatch (declaringType=System.Collections.Generic.List`1[T], methodName =Add, methodType=, argumentTypes=(System.String))\r\n```\r\n\r\nTrying to use `TargetMethod` also doesn't help:\r\n```\r\n[HarmonyPatch]\r\nstatic class ListAddPatch\r\n{\r\n    private static MethodBase TargetMethod() => AccessTools.Method(typeof(List<string>), \"Add\", new[] { typeof(string) });\r\n    public static void Prefix(List<string> __instance) => Console.WriteLine(__instance);\r\n}\r\n```\r\ngiving same result as in the first case."},"comment":{"url":"https://api.github.com/repos/pardeike/Harmony/issues/comments/459966484","html_url":"https://github.com/pardeike/Harmony/issues/156#issuecomment-459966484","issue_url":"https://api.github.com/repos/pardeike/Harmony/issues/156","id":459966484,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1OTk2NjQ4NA==","user":{"login":"alexb5dh","id":4650832,"node_id":"MDQ6VXNlcjQ2NTA4MzI=","avatar_url":"https://avatars0.githubusercontent.com/u/4650832?v=4","gravatar_id":"","url":"https://api.github.com/users/alexb5dh","html_url":"https://github.com/alexb5dh","followers_url":"https://api.github.com/users/alexb5dh/followers","following_url":"https://api.github.com/users/alexb5dh/following{/other_user}","gists_url":"https://api.github.com/users/alexb5dh/gists{/gist_id}","starred_url":"https://api.github.com/users/alexb5dh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexb5dh/subscriptions","organizations_url":"https://api.github.com/users/alexb5dh/orgs","repos_url":"https://api.github.com/users/alexb5dh/repos","events_url":"https://api.github.com/users/alexb5dh/events{/privacy}","received_events_url":"https://api.github.com/users/alexb5dh/received_events","type":"User","site_admin":false},"created_at":"2019-02-02T13:49:05Z","updated_at":"2019-02-02T13:49:05Z","author_association":"NONE","body":"I'm currently using a simple type check in the patch method:\r\n```\r\nif(__instance is List<string> list) return;\r\n```\r\nMaybe this approach can be incorporated in the Harmony as part of IL rewriting as a workaround?"}}
{"actor":{"display_login":"alexb5dh"}}