This is a migrated thread and some comments may be shown as answers.

It cuts the code after first line

3 Answers 41 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Cetin
Top achievements
Rank 1
Cetin asked on 11 May 2011, 01:24 PM
This is the C# code I tried to convert:

var usaOrders = from od in OrderDetails
where od.Order.Customer.Country == "USA"
select new {
    Company = od.Order.Customer.CompanyName,
    OrderDate = od.Order.OrderDate,
    OrderID = od.OrderID,
    Product = od.Product.ProductName,
    UnitPrice = od.UnitPrice,
    Quantity = od.Quantity,
    Discount = od.Discount,
    Extended = od.UnitPrice * od.Quantity * ( 1M - (decimal)od.Discount )
};


and this is what I got:
Dim usaOrders = _
    Where od.Order.Customer.Country = "USA"
 
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================

I expected to have something like:
Dim usaOrders = from od in OrderDetails _
    Where od.Order.Customer.Country = "USA" _
    select  _
        Company = od.Order.Customer.CompanyName, _
        OrderDate = od.Order.OrderDate, _
        OrderID = od.OrderID, _
        Product = od.Product.ProductName, _
        UnitPrice = od.UnitPrice, _
        Quantity = od.Quantity, _
        Discount = od.Discount, _
        Extended = od.UnitPrice * od.Quantity * ( 1 - od.Discount )

3 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 12 May 2011, 06:23 AM
Hello Cetin-

Unfortunately, I don't think the version of NRefactory that we're using today to do these conversions is capable of processing mutli-line LINQ statements like this. It interprets the first line as missing a ";" then ignores the rest.

LINQ syntax like this is relatively complex to convert, so I'm not sure if NRefactory has added the needed support yet. We'll definitely investigate, though, and see if a newer version of this open source engine is available to improve our conversions.

Thanks for reporting the scenario!

-Todd
0
Cetin
Top achievements
Rank 1
answered on 12 May 2011, 03:33 PM
 
It is not just the first line, sorry for misguiding you. It can't convert the simplest linq statement if it is in comprehension syntax. ie:

int[] numbers = {1,3,4,5,6};
var data = from n in numbers select n;

Luckily I don't need conversion myself and was trying to help to a VB user :) I know that I shouldn't ask for anything for a free utility just wanted to warn you if you would think fixing it.

PS: I found another converter which works for the most part (it needs manual edit too but for a word or two):

http://www.developerfusion.com/tools/convert/csharp-to-vb/
0
Todd Anglin
Top achievements
Rank 2
answered on 12 May 2011, 04:47 PM
Thanks, Cetin.

Yes, I think NRefactory cannot in general convert the LINQ Query syntax. We'll research the progress NRefactory has made in being able to interpret and convert this code and add support for it as soon as it is available.

Thanks again for reporting the scenario. Hopefully we'll be able to offer better LINQ Query conversion support soon.

-Todd
Tags
Ajax
Asked by
Cetin
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Cetin
Top achievements
Rank 1
Share this question
or