.net - Syntax error in `New SomeClass { Key .SomeProperty = SomeValue }` after C# -> VB conversion -


a co-worker of mine , both programming. has made class in c# , working on converting vb.net. got full class converted except single line, , @ point cannot figure out thought fresh set of eyes maybe able find error.

original c# code

using (var client = new httpclient(new httpclienthandler { automaticdecompression = decompressionmethods.gzip | decompressionmethods.deflate }))  

converted vb.net code

using client = new httpclient(new httpclienthandler {key .automaticdecompression = decompressionmethods.gzip or decompressionmethods.deflate}) 

error name of field or property being initialized in object initialize must start '.'.

error located under 'key'

last note: used dreaded code-converter of it, unsure 'key' came from.

there 2 concepts have similar syntax different semantics:

anonymous types

c#: new { = 1, b = 2 }

vb: new { key .a = 1, key .b = 2 }

here, vb also allows add mutable (non-key) properties, c# not support:

new { key .a = 1, key .b = 2, .somemutableproperty = 3 }

hence, key keyword important here.

object initializers named types

c#: new myclass { = 1, b = 2 }

vb: new myclass { .a = 1, .b = 2 }

here, existing properties of myclass set, key keyword irrelevant, and, thus, not allowed.


apparently, c# -> vb converter thought anonymous type, although object initializer. remove key keyword , send bug report converter's developer.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -