question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VB -> C#: Converter takes the property name from interface instead of the concrete class.

See original GitHub issue

Input code

Here is the code: https://github.com/Yozer/VBConverterBug Converting project ToConvert results in code that doesn’t compile.

Erroneous output

            var test = new Class1() { InterfaceProperty = "xxx" };
            Console.WriteLine(test.InterfaceProperty);

Expected output

            var test = new Class1() { OtherProperty = "xxx" };
            Console.WriteLine(test.OtherProperty);

Details

  • Product in use: VS extension
  • Version in use: 8.2.4
  • Did you see it working in a previous version? No
  • Any other relevant information to the issue, or your interest in contributing a fix.

Looks like the converter takes the property name from the interface instead of the concrete class.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Yozercommented, Jun 6, 2021

I don’t think my fix is correct. It works fine for me because all my interfaces and their implementations are in another project that is not being converted. For another case (when we’re converting usages, interfaces & implementations) it incorrectly renames methods.

0reactions
GrahamTheCodercommented, Jun 7, 2021

Looks good from a quick skim. I’ll have to look more closely at the condition you’ve used. I suggested TakeWhile in the hope of covering the situation where A -> B -> C, and only A and C are being converted. But that was just off the top of my head, and may not be optimal for this case or others

If you remove the “Skip” on this test, it should run locally: https://github.com/icsharpcode/CodeConverter/blob/master/Tests/CSharp/MultiFileSolutionAndProjectTests.cs#L22 (Apologies - A build server change broke it a while ago and I haven’t had time to investigate a fix for it yet). There’s a source solution which you could ensure has the vb project referencing the c# project then create a test case in

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Generic type conversion FROM string
I have a class that I want to use to store "properties" for another class. These properties simply have a name and a...
Read more >
Casting a interface to class
An explicit conversion exists (are you missing a cast?) That why I guess it means Casting Interface to Class. but what does it...
Read more >
"interface" instances should not be cast to concrete types
Needing to cast from an interface to a concrete type indicates that something is wrong with the abstractions in use, likely that something...
Read more >
How to serialize properties of derived classes with System. ...
In this article, you will learn how to serialize properties of derived classes with the System. Text. Json namespace.
Read more >
Default interface methods - C# 8.0 draft feature specifications
This feature specification describe the syntax updates necessary to support default interface methods. This includes declaring bodies in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found