C # 3.0 Anonymous Types: Naming

I was wondering if there is a way to name or rename a property of an anonymous type to include a space in the property name. For instance:

var resultSet = from customer in customerList
    select new 
    {
       FirstName = customer.firstName;
    };

In this example, I would like FirstName to be "Name". The reason for this question is because I have a user control that exposes a public DataSource property that I associate with another anonymous type. It works fine right now, except that one small drawback of column names is slightly less than user-friendly (FirstName instead of name).

+3
source share
3 answers

How to do something like this:

var resultSet = from customer in customerList
                select new 
                {
                    Value = customer.firstName,
                    Title = "First Name"
                };

"" .

+5

, , , , , ...

+3

I would add a property attribute, where you can specify your own name, and you can provide more user-friendly names using the attribute.

0
source

Source: https://habr.com/ru/post/1698428/


All Articles