{"action":"created","issue":{"url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/37","labels_url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/37/comments","events_url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/37/events","html_url":"https://github.com/jonwagner/EventSourceProxy/issues/37","id":62031698,"number":37,"title":"Validating String-Format against Method-Parameters","user":{"login":"Danielku15","id":674916,"avatar_url":"https://avatars.githubusercontent.com/u/674916?v=3","gravatar_id":"","url":"https://api.github.com/users/Danielku15","html_url":"https://github.com/Danielku15","followers_url":"https://api.github.com/users/Danielku15/followers","following_url":"https://api.github.com/users/Danielku15/following{/other_user}","gists_url":"https://api.github.com/users/Danielku15/gists{/gist_id}","starred_url":"https://api.github.com/users/Danielku15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danielku15/subscriptions","organizations_url":"https://api.github.com/users/Danielku15/orgs","repos_url":"https://api.github.com/users/Danielku15/repos","events_url":"https://api.github.com/users/Danielku15/events{/privacy}","received_events_url":"https://api.github.com/users/Danielku15/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-16T09:59:16Z","updated_at":"2015-03-21T02:20:39Z","closed_at":"2015-03-21T02:20:39Z","body":"The EventSourceProxy has the pattern that it passes all method parameters as String-Format Parameters to the EventSource. \r\n\r\nIt would be very useful if there would be a validator that checks if the String-Format Arguments match the Method Parameters. \r\n\r\n```csharp\r\npublic interface IMyLog {\r\n    [Event(0x01, Message = \"Invalid: {0}, {1}, {2}\")]\r\n    void Sample(string a, string b);\r\n}\r\n```\r\n\r\nUsing the Sample Event will fail because it has an invalid {2} Format argument. The default EventSourceAnalyzer does not handle this cases. It would be great to have an EventSourceProxy Unit-Test-Class which handles this. \r\n\r\nEDIT: I added this little code to my unit test. But it would be nice to have it (in a more clean fashion) as part of the EventSourceProxy: \r\n\r\n```csharp\r\n        private void InspectAll(EventSource eventSource)\r\n        {\r\n            var methods = eventSource.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);\r\n            foreach (var method in methods)\r\n            {\r\n                var attribute = method.GetCustomAttributes(typeof(EventAttribute), true).OfType<EventAttribute>().FirstOrDefault();\r\n                if (attribute != null)\r\n                {\r\n                    ValidateLogMethod(method, attribute);\r\n                }\r\n            }\r\n        }\r\n\r\n        private void ValidateLogMethod(MethodInfo method, EventAttribute attribute)\r\n        {\r\n            var format = attribute.Message;\r\n            ParameterInfo[] parameters = method.GetParameters();\r\n            object[] defaultValues = parameters.Select(p => Default(p.ParameterType)).ToArray();\r\n            try\r\n            {\r\n                string.Format(format, defaultValues);\r\n            }\r\n            catch (FormatException e)\r\n            {\r\n                Assert.Fail(\"Invalid string format in Log Method {0}\\r\\n {1}\", method.Name, e);\r\n            }\r\n        }\r\n\r\n        public static object Default(Type type)\r\n        {\r\n            if (type == typeof(string))\r\n            {\r\n                return string.Empty;\r\n            }\r\n\r\n            return Activator.CreateInstance(type);\r\n        }\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/comments/84219784","html_url":"https://github.com/jonwagner/EventSourceProxy/issues/37#issuecomment-84219784","issue_url":"https://api.github.com/repos/jonwagner/EventSourceProxy/issues/37","id":84219784,"user":{"login":"jonwagner","id":1652596,"avatar_url":"https://avatars.githubusercontent.com/u/1652596?v=3","gravatar_id":"","url":"https://api.github.com/users/jonwagner","html_url":"https://github.com/jonwagner","followers_url":"https://api.github.com/users/jonwagner/followers","following_url":"https://api.github.com/users/jonwagner/following{/other_user}","gists_url":"https://api.github.com/users/jonwagner/gists{/gist_id}","starred_url":"https://api.github.com/users/jonwagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonwagner/subscriptions","organizations_url":"https://api.github.com/users/jonwagner/orgs","repos_url":"https://api.github.com/users/jonwagner/repos","events_url":"https://api.github.com/users/jonwagner/events{/privacy}","received_events_url":"https://api.github.com/users/jonwagner/received_events","type":"User","site_admin":false},"created_at":"2015-03-21T02:20:39Z","updated_at":"2015-03-21T02:20:39Z","body":"This will be in the next build (hopefully this weekend)"}}