{"action":"created","issue":{"url":"https://api.github.com/repos/vexe/VFW/issues/10","labels_url":"https://api.github.com/repos/vexe/VFW/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/vexe/VFW/issues/10/comments","events_url":"https://api.github.com/repos/vexe/VFW/issues/10/events","html_url":"https://github.com/vexe/VFW/issues/10","id":71595941,"number":10,"title":"Strongly typed Invoke etc.","user":{"login":"colms","id":1678145,"avatar_url":"https://avatars.githubusercontent.com/u/1678145?v=3","gravatar_id":"","url":"https://api.github.com/users/colms","html_url":"https://github.com/colms","followers_url":"https://api.github.com/users/colms/followers","following_url":"https://api.github.com/users/colms/following{/other_user}","gists_url":"https://api.github.com/users/colms/gists{/gist_id}","starred_url":"https://api.github.com/users/colms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colms/subscriptions","organizations_url":"https://api.github.com/users/colms/orgs","repos_url":"https://api.github.com/users/colms/repos","events_url":"https://api.github.com/users/colms/events{/privacy}","received_events_url":"https://api.github.com/users/colms/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-28T13:51:28Z","updated_at":"2015-04-28T17:09:42Z","closed_at":null,"body":"I added strongly typed Invoke, InvokeRepeating etc. on my game base class. I use it because I hate passing around strings as function names because I frequently rename my functions. There is no \"nameof\" in 3.5 (introduced in 4.0) so I use the following:\r\n\r\n        public static void InvokeRepeating<T>(this MonoBehaviour mb, Func<T> method, float initialDelay, float frequency)\r\n        {\r\n            mb.InvokeRepeating(method.Method.Name, initialDelay, frequency);\r\n        }\r\n\r\n        // the same as above but for procedures instead of functions\r\n        public static void InvokeRepeating(this MonoBehaviour mb, Action method, float initialDelay, float frequency)\r\n        {\r\n            mb.InvokeRepeating(method.Method.Name, initialDelay, frequency);\r\n        }\r\n\r\n        public static void Invoke<T>(this MonoBehaviour mb, Func<T> method, float secondsDelay)\r\n        {\r\n            mb.Invoke(method.Method.Name, secondsDelay);\r\n        }\r\n\r\n        // the same as above but for procedures instead of functions\r\n        public static void Invoke(this MonoBehaviour mb, Action method, float secondsDelay)\r\n        {\r\n            mb.Invoke(method.Method.Name, secondsDelay);\r\n        }\r\n\r\nAt the moment they are extension methods but they could be overloads. I was wondering if these would be of use in BetterBehaviour. I'm not sure if it's a good fit, hence the issue instead of a pull request.\r\n\r\nCurrent usage:\r\n\r\n        void Foo()\r\n        {\r\n            callFrequencySeconds = 2.0f;\r\n            initialDelaySeconds = 1.2f;\r\n            this.InvokeRepeating(Bar, initialDelaySeconds, callFrequencySeconds);\r\n        }\r\n\r\n        void Bar()\r\n        {\r\n            print(\"Printed after a delay and called periodically\");\r\n        }\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/vexe/VFW/issues/comments/97140139","html_url":"https://github.com/vexe/VFW/issues/10#issuecomment-97140139","issue_url":"https://api.github.com/repos/vexe/VFW/issues/10","id":97140139,"user":{"login":"vexe","id":1978827,"avatar_url":"https://avatars.githubusercontent.com/u/1978827?v=3","gravatar_id":"","url":"https://api.github.com/users/vexe","html_url":"https://github.com/vexe","followers_url":"https://api.github.com/users/vexe/followers","following_url":"https://api.github.com/users/vexe/following{/other_user}","gists_url":"https://api.github.com/users/vexe/gists{/gist_id}","starred_url":"https://api.github.com/users/vexe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vexe/subscriptions","organizations_url":"https://api.github.com/users/vexe/orgs","repos_url":"https://api.github.com/users/vexe/repos","events_url":"https://api.github.com/users/vexe/events{/privacy}","received_events_url":"https://api.github.com/users/vexe/received_events","type":"User","site_admin":false},"created_at":"2015-04-28T17:09:42Z","updated_at":"2015-04-28T17:09:42Z","body":"It's a good idea. I'm not sure if it's a feature suitable to be a part of the framework since it has a not-so-obvious allocation when passing Bar. I like delegates, but the more I worked with Unity the less usage I had for them (at least at runtime) - When you're passing 'Bar' you're basically passing a new Action(Bar), allocates memory and generates garbage. Not a lot of people might know about this, for example someone coming from a C/C++ background, they might think that in C# delegates are like functions pointers and there's no cost in saying Action a = SomeMethod; but there is. So in your case, if you want 0 allocation you'd have to declare a 'BarProc' Action, set it to Bar and use it in Foo instead of Bar. I think this is a user-specific feature, so it's probably best to have it live in your personal extension methods library :)\r\n"}}