Hi,
I have the misfortune of having to convert an ArcMap AddIn to ArcGIS Pro code. Normally this isn't a problem, but this one happens to be built in VB. I'd like to copy/paste as much 'non-SDK' code as possible so I'd like to keep things in VB as opposed to converting it to my language of choice C#.
Can anyone help convert the following bit of code from C# to VB? Even googling, I can't seem to figure this out:
FeatureLayer currentLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.Equals(layerName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
Thanks
Solved! Go to Solution.
Thanks Kris,
After some more trial and error I finally got something that worked:
Dim fLayer As FeatureLayer = map.GetLayersAsFlattenedList().OfType(Of FeatureLayer)().Where(Function(l) l.Name.Equals(layerName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()
I hate VB!! 🙂
Thanks for responding and for the tips on VB convertors.
There are free converters online for C# to VB.Net but I don't know how well they will work with Linq.
Here is what I came up with:
Dim layer as FeatureLayer = map.GetLayersAsFlattenedList().OfType(Of FeatureLayer)().Where(Function(layer) layer.Name = layerName).FirstOrDefault()
To figure out the lamda expression, I searched for "lambda vb.net". You can also search for "linq vb.net" for some samples as well.
HTH.
Kris
Thanks Kris,
After some more trial and error I finally got something that worked:
Dim fLayer As FeatureLayer = map.GetLayersAsFlattenedList().OfType(Of FeatureLayer)().Where(Function(l) l.Name.Equals(layerName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()
I hate VB!! 🙂
Thanks for responding and for the tips on VB convertors.
My pleasure.
I wouldn't hate on VB. Just be happy it's not VB6 and you have to convert from VB6 to VB.NET.
Keep in mind that a lot of features currently in C# may not be available in VB.NET. That means you may have even more verbose code than you normally have with VB.NET.
If there is any way you can move to C#, I would do it. Make the case hard to the powers that be. "Technical debt" would be my biggest argument. There are far fewer VB.NET developers out there than C#. It may be "cheaper" now to stay in VB.NET but it will be far more expensive down the line.
Kris
Thanks Kris. Yes, after a couple of hours of frustration I have abandoned VB and will for a full re-write in C#. As you said, probably better to do it ASAP.
Thanks!