Custodio
Custodio

Reputation: 8934

Converting LINQ statement from query to fluent c# syntax

Hey, I'm stuck in a converting a simple Linq statement from query syntax to fluent syntax in C#. I think that is possible, but I need a hint.

from property in target.GetType().GetProperties()
select new
{
   Name = property.Name,
   Value = property.GetValue(target, null)
};

to..

var props = target.GetType().GetProperties().Select(p=>p.Name.... )

What I need change after Select?

Upvotes: 1

Views: 1698

Answers (2)

cwharris
cwharris

Reputation: 18125

var props = target.GetType()
                  .GetProperties()
                  .Select(p => new {
                      Name = p.Name,
                      Value = p.GetValue(target, null)
                  });

?

Upvotes: 1

David Ruttka
David Ruttka

Reputation: 14409

var props = target
    .GetType()
    .GetProperties()
    .Select(p => new { 
        Name = p.Name, 
        Value = p.GetValue(target, null)
});

Upvotes: 11

Related Questions