Vishnu Y
Vishnu Y

Reputation: 2311

Convert Linq to code using ReSharper

I have installed ReSharper 8.2.1 Full on my Visual Studio 2010 Pro and I have a requirement to convert the Linq to foreach. I found this article on their help site which tells like Converting a linq expression to code is possible with Resharper.

when I opened my application in Visual Studio and Placed the caret at the query expression and pressed Alt+Enter, I can see the "Convert Linq to method chain" but the other option "Convert Linq to code" is missing. Do I need to add any settings to make it work? Have anyone tried this option?

Upvotes: 3

Views: 4312

Answers (2)

Cai Weichuang
Cai Weichuang

Reputation: 1

    var data = lines
        .Skip(1)
        .Select(p=>p.Split(','))
        .GroupBy(p=>p[0])
        .Select((p,i)=>new Datastore.QuizCategory{
            Id = i+1,
            Name = p.Key,
            QuizQuestions = p.Select(pp=>new QuizQuestion{
                Question = pp[1],
                Options = pp[2].Replace("\uff1b", ";").Split(";"),
                Answers = pp[3].Replace("\uff1b", ";").Split(";")
                    .Where(p=>string.IsNullOrEmpty(p)==false)
                    .Select(ppp=>int.Parse(ppp))
                    .ToArray()
            }).ToArray()
        }).ToArray();

Upvotes: 0

citizenmatt
citizenmatt

Reputation: 18573

"Convert LINQ to code" only works with certain expression patterns, like a foreach statement or a return statement that can be converted into a loop with yield return. What's your code block?

Upvotes: 3

Related Questions