public class TimeZone
{
public int Id { get; set; }
public string DisplayName{ get; set; }
}
In some other class I've:
var gmtList = new SelectList(
repository.GetSystemTimeZones(),
"Id",
"DisplayName");
Note: System.Web.Mvc.SelectList
I do not like to have to write the property name with "Id" and "DisplayName". Later in time, maybe the property name will change and the compiler will not detect this error. C# how to get property name in a string?
UPDATE 1
With the help of Christian Hayter, I can use:
var tz = new TimeZone();
var gmtList = new SelectList(
repository.GetSystemTimeZones(),
NameOf(() => tz.Id),
NameOf(() => tz.TranslatedName));
OR
var gmtList = new SelectList(
repository.GetSystemTimeZones(),
NameOf(() => new TimeZone().Id),
NameOf(() => new TimeZone().TranslatedName));
If someone has other idea without the need of creating a new object. Feel free to share it :) thank you.