-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
#region preprocessor directives not converted #15
Comments
I add one string of code if (attrList.Target != null) {
if (SyntaxTokenExtensions.IsKind((SyntaxToken)attrList.Target?.Identifier, CS.SyntaxKind.ReturnKeyword) == true)
retAttr.Add((AttributeListSyntax)attrList.Accept(this));
else
attr.Add((AttributeListSyntax)attrList.Accept(this));
} But all this project has built in crazy and insecure style. I'm don't understand this style of programming
are you have understanding that in any moment Obj1 may equal null, or Obj2 in any moment may equal null ... hmmm .... VB-programmer usually use only one variable in one operator, and in top of each sub or function before doing sensitive function need to check all parameters to correct value. And if possible need don't use expression future. This is my style, and I usually working as freelancer and I see thousands of VB-project. I think this is main stream of style of VB-programmer - firstly check any variable on top of function and after that use less as possible variables in one code string. Sorry, my friend, for this description, but I really don't understand your style of programming. and second problem in shallow view - its support not all C# and VB syntax - for example directive #define this project fully ignore. Very sorry. |
Thank you for including example code and error message, that's very helpful! You are correct that some language features like this are still unsupported. Over time (and with the help of the community) we hope to cover much more. If you intend to work on implementing The code style makes frequent use of the reasonably new operator |
As of 5.6.1, the attribute issue is fixed. Preprocessor directives are still not supported so I'll leave this issue open to track that. It may be extremely difficult to correctly convert preprocessor directives in cases such as this: #8 (comment) |
After looking more closely at what's available in Roslyn, even this looks to be a challenge. If Roslyn will deal with a bit of ambiguity it might yield acceptable results for simple cases, to just discover all constants, and set them all to true, which I'll try out some time, but anything more is definitely going to be punted way down the line. There are some other preprocessor directives such as enabling/disabling warnings that should be much easier to convert. |
I am also having an issue converted from C# to VB with the #region and #endregion not working. |
@kathleenwest Thanks for reminder, I actually need to update some of the details of this issue. Doesn't convert correctly: #region MyClass definition
public class MyClass
{
static void Main()
{
}
}
#endregion Does convert correctly: using System;
#region MyClass definition
public class MyClass
{
static void Main()
{
}
}
#endregion If you're seeing a similar issue, perhaps this will help you work around the issue until there's a fix. Otherwise, could you post a bit more detail on the input or issue with the output? Thanks! |
Also, I learned that VB does not allow the similar #region #endregion inside the methods.. so that probably needs to be ignored by the code converter and commented out if it exists in C#. |
Ah I wasn't aware of that difference, thanks! |
Can you update us on where you are with this (VB -> C#), as I use As an interim measure, I think it would be helpful for these 'trivia' (!) to output the original directive along with the error message in the target code. At least then it would be easier to reconstruct the desired directive manually, without having to do a side-by-side comparison with the original. |
@rlktradewright The best work around I discovered so far is to just comment out the #region directives in C# before converting to VB. I also learned that VB language rules does not allow #region directives inside methods, only outside... so that may be a reason why the conversion fails. |
Thanks for that, though it's the opposite direction I'm concerned with VB to C#. But you're right: I should just comment out all the #Region and #End Region directives in the VB and then use a single regular expression search and replace to convert them in the C#. Since I can do that for an entire solution with one edit, it's really not a problem. Still, it would nice not to have to do this.... |
Would it help to include some of these regex hacks in this tool? Stuff like
|
Yeah, good thinking, maybe a partial workaround would be a quick win. I'll see what I can do to move this forward in some way. |
@kathleenwest I've just tried region statements within a VB method block and they appear to be valid now. Some sources online suggest that this works from VS2015 onwards, though I couldn't find a language specification from those versions to confirm. However, this doesn't mean the languages are equivalent. C# actually allows regions around basically any tokens. Console
#region Just a dot
.
#endregion
WriteLine(
#region Spoilers abound
"Hello World!")
#endregion
; ^ I hope no-one ever writes code that looks like this! |
@GrahamTheCoder I wouldn't be surprised if that works in newer versions of VS and not in older versions. My employer (now former) was making me do their C# and VB code in an older licensed version of VS and an older compiler. 😩 |
@kathleenwest oh dear, congratulations on the upgrade! ☺ |
Hey, anything new here? ☺ |
Previously there was a general base piece of work this issue required to allow any of these to be worked on. That's done, but the specific cases still need work on top of that. Region directives now work in many common cases. They were the main focus of chat in this issue, so I'll close it. They will likely always be slightly imperfect and need a bit of post conversion tidying but I think it's best to open bugs for specific cases with those now. #Pragma directives have had no attention, I've added them to known issues since they're rarely mentioned and complex enough not to be worth the effort in general, but there may be a couple of common cases worth covering in a dedicated PR. Or a wiki page with a few regexes. #if statements' contents still aren't converted. For C# to VB I've added this to known issues since it's very unlikely anyone will ever tackle that. For VB to C#, I've reopened #863 to track it Please follow #863 or open an appropriate issue if there's a specific case you think is important. Thanks! |
Sorry, my friend, this is very interesting project to me, because I write in rare lang VB.NET, but any call your converter induce error below. This is input C# code for call this issue ( from wordwide C# example "contoso university").
Also I start your project in source code and see a code line number with error. Please see below.
The text was updated successfully, but these errors were encountered: