CodeConverter
CodeConverter copied to clipboard
VB -> C#: CS0115 no suitable method found to override
Input code
Protected Overridable ReadOnly Property AutoClearEnabledQueryCommand As String
Erroneous output
protected virtual string AutoClearEnabledQueryCommand { get; private set; }
Expected output
protected virtual string AutoClearEnabledQueryCommand { get; set; }
Details
- Product in use: both
- Version in use: 8.2.1
- Did you see it working in a previous version, which? n/a
- Any other relevant information to the issue, or your interest in contributing a fix. Clearly, this seems to expose another conflict between VB and C#, which entails a breaking change.
CS0115 appears on the 'set' element.
It seems that the C# implementation would work if the VB code property is changed to Read/Write.
Protected Overridable Property AutoClearEnabledQueryCommand As String
protected virtual string AutoClearEnabledQueryCommand { get; set; }
If the VB code is not changed before the conversion, the converted code is bound to cause a breaking change. What is implemented on the converter side, then, is a matter of style and perhaps could be informed by having a set of configuration settings. Such settings could also be used, for example, to address the issue of the resources: replace or add in root.
It would seems if the VB cothat the VB code My take is that the VB code needs to change before conversion
I don't think this needs to be a breaking change. The set can be omitted, it's just that we'd need to separately declare a backing field if someone assigns to the backing field of the readonly property, example.
The current addition of a private setter was a workaround to avoid that more verbose output - and to avoid detecting if the _PropertyName syntax was used.
the backing field is compiler-generated in VB.Net. Is it generated in C#?
With this test code: < private string Bar { get; } [Fact] public void WriteReadOnlyField() { _Bar = "Bar"; }
I get SCS0103 The name '_Foo' does not exist in the current context. This is both under .Net 5.0 (C# 9(?)) and Core 3.0.
Yes the backing field is generated, but there's no syntax to read write directly. But we could explicitly create the field in the conversion with the underscore name (and make the readonly property simply return it)
Per MSDN (reading on stack overflow), the backing field is accessible only from the get and set functions of the property. I guess that is how the automated property is generated. So indeed, the non-breaking solution would be for the conversion to imitate VB.Net, which exposes the backing property.
May I take this opportunity to thank you, again, for this superb project, which enabled me to both transform my VB code and learn so much about C#. Wishing you a great new year. David
From: GrahamTheCoder [email protected] Sent: Wednesday, December 23, 2020 3:16:53 PM To: icsharpcode/CodeConverter [email protected] Cc: David Hary [email protected]; Author [email protected] Subject: Re: [icsharpcode/CodeConverter] VB -> C#: CS0115 no suitable method found to override (#685)
Yes the backing field is generated, but there's no syntax to read write directly. But we could explicitly create the field in the conversion with the underscore name
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ficsharpcode%2FCodeConverter%2Fissues%2F685%23issuecomment-750546270&data=04%7C01%7C%7Ced19e85a333744b5a2af08d8a798d5e9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637443622144998638%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=c8W1TYC0UgGdGAxgn0l6Xq5pPkJcFhzrLUR5aPHoHKM%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAGBGSRITFMIUV3KCF2MT33SWJ26LANCNFSM4UIMGQHA&data=04%7C01%7C%7Ced19e85a333744b5a2af08d8a798d5e9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637443622144998638%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=elquRc4u01Y5wX1NXZW5AED0lVX5K3Xeli1PE5JA3lE%3D&reserved=0.