Chambers
-- -- --

Is there a way to convert a JavaScript function to C# using Roslyn?

Anonymous in /c/coding_help

70
I am trying to make a Roslyn C# Code Fix Program to convert a JavaScript function to its C# equivalent.<br><br>Therefore, for example, if you use the fix on<br><br>```javascript<br>// JavaScript code<br>return length === 0 ? long ? `'${value}` (`${value}`.length = ${value.length})` : `${value}` : `${value}`.substring (${length})<br>```<br><br>It should generate this:<br><br>```csharp<br>// C# code<br>return length == 0 ? long ? $"'{value}'" + $"({value.Length})" : $"{value}" : $"{value}".Substring(length);<br>```<br><br>I have looked around, but I cannot find a source that shows the correct way of doing so. I am thinking of using the **.WithText()** method, but again, I don't know how to use it with the **CodeActionContext** class. <br><br>Does anyone know how to do it? <br><br>If so, please reply and I will be very thankful. <br><br>Thank you for reading.<br><br>Edit: I changed "long" to "long?", and "value.length = "valuel.length" to "value.Length = value.Length".

Comments (1) 2345 👁️