{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/5190","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/5190/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/5190/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/5190/events","html_url":"https://github.com/dotnet/roslyn/issues/5190","id":106142726,"number":5190,"title":"Question: How to I modify a VB ForStatementSyntax","user":{"login":"paul1956","id":12789369,"avatar_url":"https://avatars.githubusercontent.com/u/12789369?v=3","gravatar_id":"","url":"https://api.github.com/users/paul1956","html_url":"https://github.com/paul1956","followers_url":"https://api.github.com/users/paul1956/followers","following_url":"https://api.github.com/users/paul1956/following{/other_user}","gists_url":"https://api.github.com/users/paul1956/gists{/gist_id}","starred_url":"https://api.github.com/users/paul1956/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paul1956/subscriptions","organizations_url":"https://api.github.com/users/paul1956/orgs","repos_url":"https://api.github.com/users/paul1956/repos","events_url":"https://api.github.com/users/paul1956/events{/privacy}","received_events_url":"https://api.github.com/users/paul1956/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/API","name":"API","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Question","name":"Question","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Up%20for%20Grabs","name":"Up for Grabs","color":"90EE90"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/2","html_url":"https://github.com/dotnet/roslyn/milestones/Unknown","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/2/labels","id":937398,"number":2,"title":"Unknown","description":"This represents work which is not planned for a specific release.\r\n\r\n<!---\r\n@huboard:{\"order\":0.25}\n-->\r\n","creator":{"login":"jaredpar","id":146967,"avatar_url":"https://avatars.githubusercontent.com/u/146967?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredpar","html_url":"https://github.com/jaredpar","followers_url":"https://api.github.com/users/jaredpar/followers","following_url":"https://api.github.com/users/jaredpar/following{/other_user}","gists_url":"https://api.github.com/users/jaredpar/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredpar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredpar/subscriptions","organizations_url":"https://api.github.com/users/jaredpar/orgs","repos_url":"https://api.github.com/users/jaredpar/repos","events_url":"https://api.github.com/users/jaredpar/events{/privacy}","received_events_url":"https://api.github.com/users/jaredpar/received_events","type":"User","site_admin":false},"open_issues":385,"closed_issues":102,"state":"open","created_at":"2015-01-15T20:46:02Z","updated_at":"2015-11-17T19:53:48Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2015-09-12T09:15:10Z","updated_at":"2015-11-17T19:53:48Z","closed_at":"2015-11-17T19:53:48Z","body":"I am trying to add the missing Type information, I am having trouble replacing the Control Variable with anything. I can't find a SyntaxFactory.ControlVariable. And it I try to use VariableDeclarator to replace the ControlVariable Node, I can't convert the original ControlVariable to a SeparatedSyntaxList(Of ModifiedIdentifierSyntax)., and I don't know if that will actually work.\r\n\r\nIf this is not the appropriate place to ask How To questions, where should this type of question be asked. I have scanned the Source but I can't find examples for anything like this."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/157487045","html_url":"https://github.com/dotnet/roslyn/issues/5190#issuecomment-157487045","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/5190","id":157487045,"user":{"login":"AnthonyDGreen","id":10539978,"avatar_url":"https://avatars.githubusercontent.com/u/10539978?v=3","gravatar_id":"","url":"https://api.github.com/users/AnthonyDGreen","html_url":"https://github.com/AnthonyDGreen","followers_url":"https://api.github.com/users/AnthonyDGreen/followers","following_url":"https://api.github.com/users/AnthonyDGreen/following{/other_user}","gists_url":"https://api.github.com/users/AnthonyDGreen/gists{/gist_id}","starred_url":"https://api.github.com/users/AnthonyDGreen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnthonyDGreen/subscriptions","organizations_url":"https://api.github.com/users/AnthonyDGreen/orgs","repos_url":"https://api.github.com/users/AnthonyDGreen/repos","events_url":"https://api.github.com/users/AnthonyDGreen/events{/privacy}","received_events_url":"https://api.github.com/users/AnthonyDGreen/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T19:53:48Z","updated_at":"2015-11-17T19:53:48Z","body":"@paul1956,\r\n\r\nSorry, I hadn't noticed this before. When you write this:\r\n\r\n```VB.NET\r\nFor i = 1 To 10\r\nNext\r\n```\r\n\r\nThe way that's represented is that the 'i' is a reference to an implicitly declared local variable. It's not a declaration itself. Syntactically it has to be that way because if 'i' were a local variable, parameter, field (or anything really) in scope 'i' would bind to it, not create a new variable. For that reason, when there isn't an 'As' clause syntactically it's just an IdentifierNameSyntax. By convention IdentifierNames always represent a reference to a symbol, never a declaration.\r\n\r\nNow, when one writes:\r\n\r\n```VB.NET\r\nFor i As Integer = 1 To 10\r\nNext\r\n```\r\n\r\nThe 'i As Integer' part is unambiguously a declaration and is represented by a VariableDeclarator node. This is the same node used in local variable and field declarations. It contains a list of modified identifiers because such statements could take the form of:\r\n\r\n```VB.NET\r\nDim x, y, z As Integer\r\n```\r\n\r\nAnd even more convoluted:\r\n\r\n```VB.NET\r\nDim x?, y(), z As Integer ' Declares three variables of type Integer?, Integer(), and Integer\r\n```\r\n \r\nThe ? and () modifiers on the base identifier token is why we have the ModifiedIdentifierSyntax node. ModifiedIdentifiers are always declarations and have no relation to the IdentifierNameSyntax. The only thing they share is an identifier token.\r\n\r\nSo to correctly convert from one to the other you'd write something like:\r\n\r\n```VB.NET\r\nImports Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory\r\n\r\nDim oldControlVariable As IdentifierNameSyntax = forStatement.ControlVariable\r\nDim newControlVariable =\r\n        VariableDeclarator(\r\n            SingletonSeparatedList(ModifiedIdentifier(oldControlVariable.Identifier)),\r\n            SimpleAsClause(PredefinedType(Token(SyntaxKind.IntegerKeyword))),\r\n            initializer:=Nothing\r\n        )\r\n\r\nforStatement = forStatement.WithControlVariable(newControlVariable)\r\n```\r\n\r\nThat takes the original identifier content and inserts it in a new declaration.\r\n\r\nI doubt you've been blocked on this for two months but hopefully that provides some background to you and/or whomever might stumble on this thread later.\r\n\r\nRegards,\r\n\r\n**-ADG**"}}