DEV Community

Discussion on: Safer C# with the nameof operator

Collapse
 
buinauskas profile image
Evaldas Buinauskas • Edited

I love this, it becomes really useful for Dapper(or any other raw SQL) statements to guarantee properly mapped objects.

var sql = $@"
    SELECT
        CustomerId AS {nameof(Customer.Id)}
      , CustomerName AS {nameof(Customer.Name)}
      , CustomerBalance AS {nameof(Customer.Balance)}
    FROM dbo.Customers
    WHERE CustomerId = @CustomerId;";
Collapse
 
integerman profile image
Matt Eland

Oh that's fantastic. I hadn't even thought of that use case. Love it!