It cuts the code after first line

4 posts, 0 answers
  1. Cetin
    Cetin avatar
    2 posts
    Member since:
    May 2011

    Posted 11 May 2011 Link to this post

    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 )

  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 12 May 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Cetin
    Cetin avatar
    2 posts
    Member since:
    May 2011

    Posted 12 May 2011 Link to this post

     
    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/
  5. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 12 May 2011 Link to this post

    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
Back to Top