{"action":"created","comment":{"url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/comments/90122045","pull_request_review_id":10646506,"id":90122045,"diff_hunk":"@@ -8,31 +9,51 @@ public sealed class Command<T> : Command\n \t\tpublic Command(Action<T> execute) \n \t\t\t: base(o =>\n \t\t\t{\n-\t\t\t\tif (o is T)\n+\t\t\t\tif (IsValidParameter(o))\n \t\t\t\t{\n \t\t\t\t\texecute((T)o);\n \t\t\t\t}\n \t\t\t})\n \t\t{\n \t\t\tif (execute == null)\n \t\t\t{\n-\t\t\t\tthrow new ArgumentNullException(\"execute\");\n+\t\t\t\tthrow new ArgumentNullException(nameof(execute));\n \t\t\t}\n \t\t}\n \n \t\tpublic Command(Action<T> execute, Func<T, bool> canExecute) \n \t\t\t: base(o =>\n \t\t\t{\n-\t\t\t\tif (o is T)\n+\t\t\t\tif (IsValidParameter(o))\n \t\t\t\t{\n \t\t\t\t\texecute((T)o);\n \t\t\t\t}\n-\t\t\t}, o => o is T && canExecute((T)o))\n+\t\t\t}, o => IsValidParameter(o) && canExecute((T)o))\n \t\t{\n \t\t\tif (execute == null)\n-\t\t\t\tthrow new ArgumentNullException(\"execute\");\n+\t\t\t\tthrow new ArgumentNullException(nameof(execute));\n \t\t\tif (canExecute == null)\n-\t\t\t\tthrow new ArgumentNullException(\"canExecute\");\n+\t\t\t\tthrow new ArgumentNullException(nameof(canExecute));\n+\t\t}\n+\n+\t\tstatic bool IsValidParameter(object o)\n+\t\t{\n+\t\t\tif (o != null)\n+\t\t\t{\n+\t\t\t\t// The parameter isn't null, so we don't have to worry whether null is a valid option\n+\t\t\t\treturn o is T;\n+\t\t\t}\n+\n+\t\t\tvar t = typeof(T);\n+\n+\t\t\t// The parameter is null. Is T Nullable?\n+\t\t\tif (Nullable.GetUnderlyingType(t) != null)\n+\t\t\t{\n+\t\t\t\treturn true;\n+\t\t\t}\n+\n+\t\t\t// Not a Nullable, if it's a value type then null is not valid\n+\t\t\treturn !t.GetTypeInfo().IsValueType;","path":"Xamarin.Forms.Core/Command.cs","position":62,"original_position":60,"commit_id":"af95f48b388a210ff1fe3b8f7913d43ac50e85c5","original_commit_id":"af95f48b388a210ff1fe3b8f7913d43ac50e85c5","user":{"login":"StephaneDelcroix","id":313003,"avatar_url":"https://avatars.githubusercontent.com/u/313003?v=3","gravatar_id":"","url":"https://api.github.com/users/StephaneDelcroix","html_url":"https://github.com/StephaneDelcroix","followers_url":"https://api.github.com/users/StephaneDelcroix/followers","following_url":"https://api.github.com/users/StephaneDelcroix/following{/other_user}","gists_url":"https://api.github.com/users/StephaneDelcroix/gists{/gist_id}","starred_url":"https://api.github.com/users/StephaneDelcroix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StephaneDelcroix/subscriptions","organizations_url":"https://api.github.com/users/StephaneDelcroix/orgs","repos_url":"https://api.github.com/users/StephaneDelcroix/repos","events_url":"https://api.github.com/users/StephaneDelcroix/events{/privacy}","received_events_url":"https://api.github.com/users/StephaneDelcroix/received_events","type":"User","site_admin":false},"body":"I'd swap the 2 checks. first check if it's a reference type, and if it's not, start to wonder about Nullable...","created_at":"2016-11-29T21:49:04Z","updated_at":"2016-11-29T21:50:16Z","html_url":"https://github.com/xamarin/Xamarin.Forms/pull/572#discussion_r90122045","pull_request_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572","_links":{"self":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/comments/90122045"},"html":{"href":"https://github.com/xamarin/Xamarin.Forms/pull/572#discussion_r90122045"},"pull_request":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572"}}},"pull_request":{"url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572","id":95628600,"html_url":"https://github.com/xamarin/Xamarin.Forms/pull/572","diff_url":"https://github.com/xamarin/Xamarin.Forms/pull/572.diff","patch_url":"https://github.com/xamarin/Xamarin.Forms/pull/572.patch","issue_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/572","number":572,"state":"open","locked":false,"title":"Allow Command CanExecute to recover when run on inherited bindingcontext","user":{"login":"hartez","id":538025,"avatar_url":"https://avatars.githubusercontent.com/u/538025?v=3","gravatar_id":"","url":"https://api.github.com/users/hartez","html_url":"https://github.com/hartez","followers_url":"https://api.github.com/users/hartez/followers","following_url":"https://api.github.com/users/hartez/following{/other_user}","gists_url":"https://api.github.com/users/hartez/gists{/gist_id}","starred_url":"https://api.github.com/users/hartez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hartez/subscriptions","organizations_url":"https://api.github.com/users/hartez/orgs","repos_url":"https://api.github.com/users/hartez/repos","events_url":"https://api.github.com/users/hartez/events{/privacy}","received_events_url":"https://api.github.com/users/hartez/received_events","type":"User","site_admin":false},"body":"### Description of Change ###\r\n\r\nOn WinRT/UWP during the process of binding, items in a `ListView` initially inherit the binding context of the `ListView` before getting a more specific binding context. If the `DataTemplate` of the `ListView` includes an item which has both \r\n\r\n- a bound `Command` which includes a `CanExecute` method and\r\n- a bound `CommandParameter`\r\n\r\nthe initial binding of the item will trigger a check on the `CanExecute` method (to determine if `IsEnabled` should be true). The `CanExecute` method attempts to cast the binding context to the correct type and throws an `InvalidCastException`. The `InvalidCastException` is not fatal, but it causes the rest of the `DataTemplate` binding to fail, and the `ListView` items will appear blank (though in the most recent version of XF they are still tappable). \r\n\r\nThis change checks the type before executing the command and does not execute the command if the type is incorrect; it also checks the type before checking `CanExecute` and returns `false` if the type is incorrect.\r\n\r\n### Bugs Fixed ###\r\n\r\n- [47971 – XF UWP ListView Items no longer display ImageCell is the problem](https://bugzilla.xamarin.com/show_bug.cgi?id=47971)\r\n\r\n### API Changes ###\r\n\r\nList all API changes here (or just put None), example:\r\n\r\nNone\r\n\r\n### Behavioral Changes ###\r\n\r\nNone\r\n\r\n### PR Checklist ###\r\n\r\n- [x] Has tests (if omitted, state reason in description)\r\n- [x] Rebased on top of master at time of PR\r\n- [x] Changes adhere to coding standard\r\n- [x] Consolidate commits as makes sense\r\n\r\n","created_at":"2016-11-29T05:25:07Z","updated_at":"2016-11-29T21:50:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"814725c80c8db661ecc81a023e7b634669591377","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572/commits","review_comments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572/comments","review_comment_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/572/comments","statuses_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/statuses/af95f48b388a210ff1fe3b8f7913d43ac50e85c5","head":{"label":"xamarin:fix-bugzilla47971","ref":"fix-bugzilla47971","sha":"af95f48b388a210ff1fe3b8f7913d43ac50e85c5","user":{"login":"xamarin","id":790012,"avatar_url":"https://avatars.githubusercontent.com/u/790012?v=3","gravatar_id":"","url":"https://api.github.com/users/xamarin","html_url":"https://github.com/xamarin","followers_url":"https://api.github.com/users/xamarin/followers","following_url":"https://api.github.com/users/xamarin/following{/other_user}","gists_url":"https://api.github.com/users/xamarin/gists{/gist_id}","starred_url":"https://api.github.com/users/xamarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xamarin/subscriptions","organizations_url":"https://api.github.com/users/xamarin/orgs","repos_url":"https://api.github.com/users/xamarin/repos","events_url":"https://api.github.com/users/xamarin/events{/privacy}","received_events_url":"https://api.github.com/users/xamarin/received_events","type":"Organization","site_admin":false},"repo":{"id":54213490,"name":"Xamarin.Forms","full_name":"xamarin/Xamarin.Forms","owner":{"login":"xamarin","id":790012,"avatar_url":"https://avatars.githubusercontent.com/u/790012?v=3","gravatar_id":"","url":"https://api.github.com/users/xamarin","html_url":"https://github.com/xamarin","followers_url":"https://api.github.com/users/xamarin/followers","following_url":"https://api.github.com/users/xamarin/following{/other_user}","gists_url":"https://api.github.com/users/xamarin/gists{/gist_id}","starred_url":"https://api.github.com/users/xamarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xamarin/subscriptions","organizations_url":"https://api.github.com/users/xamarin/orgs","repos_url":"https://api.github.com/users/xamarin/repos","events_url":"https://api.github.com/users/xamarin/events{/privacy}","received_events_url":"https://api.github.com/users/xamarin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xamarin/Xamarin.Forms","description":"Xamarin.Forms official home","fork":false,"url":"https://api.github.com/repos/xamarin/Xamarin.Forms","forks_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/forks","keys_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/teams","hooks_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/hooks","issue_events_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/events{/number}","events_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/events","assignees_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/assignees{/user}","branches_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/branches{/branch}","tags_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/tags","blobs_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/refs{/sha}","trees_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/statuses/{sha}","languages_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/languages","stargazers_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/stargazers","contributors_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/contributors","subscribers_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/subscribers","subscription_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/subscription","commits_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/commits{/sha}","git_commits_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/commits{/sha}","comments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/comments{/number}","issue_comment_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/comments{/number}","contents_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/contents/{+path}","compare_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/merges","archive_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/downloads","issues_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues{/number}","pulls_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls{/number}","milestones_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/milestones{/number}","notifications_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/labels{/name}","releases_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/releases{/id}","deployments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/deployments","created_at":"2016-03-18T15:52:03Z","updated_at":"2016-11-29T11:48:57Z","pushed_at":"2016-11-29T21:37:57Z","git_url":"git://github.com/xamarin/Xamarin.Forms.git","ssh_url":"git@github.com:xamarin/Xamarin.Forms.git","clone_url":"https://github.com/xamarin/Xamarin.Forms.git","svn_url":"https://github.com/xamarin/Xamarin.Forms","homepage":"https://xamarin.com/forms","size":30183,"stargazers_count":1028,"watchers_count":1028,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":374,"mirror_url":null,"open_issues_count":73,"forks":374,"open_issues":73,"watchers":1028,"default_branch":"master"}},"base":{"label":"xamarin:master","ref":"master","sha":"f8bdfd334716cc1887c48d482beb809330774580","user":{"login":"xamarin","id":790012,"avatar_url":"https://avatars.githubusercontent.com/u/790012?v=3","gravatar_id":"","url":"https://api.github.com/users/xamarin","html_url":"https://github.com/xamarin","followers_url":"https://api.github.com/users/xamarin/followers","following_url":"https://api.github.com/users/xamarin/following{/other_user}","gists_url":"https://api.github.com/users/xamarin/gists{/gist_id}","starred_url":"https://api.github.com/users/xamarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xamarin/subscriptions","organizations_url":"https://api.github.com/users/xamarin/orgs","repos_url":"https://api.github.com/users/xamarin/repos","events_url":"https://api.github.com/users/xamarin/events{/privacy}","received_events_url":"https://api.github.com/users/xamarin/received_events","type":"Organization","site_admin":false},"repo":{"id":54213490,"name":"Xamarin.Forms","full_name":"xamarin/Xamarin.Forms","owner":{"login":"xamarin","id":790012,"avatar_url":"https://avatars.githubusercontent.com/u/790012?v=3","gravatar_id":"","url":"https://api.github.com/users/xamarin","html_url":"https://github.com/xamarin","followers_url":"https://api.github.com/users/xamarin/followers","following_url":"https://api.github.com/users/xamarin/following{/other_user}","gists_url":"https://api.github.com/users/xamarin/gists{/gist_id}","starred_url":"https://api.github.com/users/xamarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xamarin/subscriptions","organizations_url":"https://api.github.com/users/xamarin/orgs","repos_url":"https://api.github.com/users/xamarin/repos","events_url":"https://api.github.com/users/xamarin/events{/privacy}","received_events_url":"https://api.github.com/users/xamarin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xamarin/Xamarin.Forms","description":"Xamarin.Forms official home","fork":false,"url":"https://api.github.com/repos/xamarin/Xamarin.Forms","forks_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/forks","keys_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/teams","hooks_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/hooks","issue_events_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/events{/number}","events_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/events","assignees_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/assignees{/user}","branches_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/branches{/branch}","tags_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/tags","blobs_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/refs{/sha}","trees_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/statuses/{sha}","languages_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/languages","stargazers_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/stargazers","contributors_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/contributors","subscribers_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/subscribers","subscription_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/subscription","commits_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/commits{/sha}","git_commits_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/git/commits{/sha}","comments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/comments{/number}","issue_comment_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/comments{/number}","contents_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/contents/{+path}","compare_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/merges","archive_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/downloads","issues_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues{/number}","pulls_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls{/number}","milestones_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/milestones{/number}","notifications_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/labels{/name}","releases_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/releases{/id}","deployments_url":"https://api.github.com/repos/xamarin/Xamarin.Forms/deployments","created_at":"2016-03-18T15:52:03Z","updated_at":"2016-11-29T11:48:57Z","pushed_at":"2016-11-29T21:37:57Z","git_url":"git://github.com/xamarin/Xamarin.Forms.git","ssh_url":"git@github.com:xamarin/Xamarin.Forms.git","clone_url":"https://github.com/xamarin/Xamarin.Forms.git","svn_url":"https://github.com/xamarin/Xamarin.Forms","homepage":"https://xamarin.com/forms","size":30183,"stargazers_count":1028,"watchers_count":1028,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":374,"mirror_url":null,"open_issues_count":73,"forks":374,"open_issues":73,"watchers":1028,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572"},"html":{"href":"https://github.com/xamarin/Xamarin.Forms/pull/572"},"issue":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/572"},"comments":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/issues/572/comments"},"review_comments":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572/comments"},"review_comment":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/pulls/572/commits"},"statuses":{"href":"https://api.github.com/repos/xamarin/Xamarin.Forms/statuses/af95f48b388a210ff1fe3b8f7913d43ac50e85c5"}}}}
{"actor":{"display_login":"StephaneDelcroix"}}