我有一堂课
public class SearchDocument
{
public string[] CustomerNames { get; set; }
public SearchCustomerPerson[] CustomerPersons { get; set; }
}
SearchCustomerPerson类
public class SearchCustomerPerson
{
public string Id { get; set; }
public string CustomerId { get; set; }
public string FirstName { get; set; }
}
我想使用nameof属性获取SearchCustomerPerson中存在的FirstName的名称。例如,我尝试过:
nameof(CustomerSearchDocument.CustomerPersons.FirstOrDefault().FirstName)
但是,当添加到字典中时,以上行会引发错误。我想创建一个强类型的属性。
我正在尝试将上述类型添加到字典中:
new Dictionary<string, string>()
{
{
nameof(PolicyNameSearchRequest.FilterOptions.FirstName),
nameof(CustomerSearchDocument.CustomerPersons.FirstOrDefault().FirstName)
},
}
nameof(CustomerSearchDocument.CustomerPersons.FirstOrDefault()。FirstName)给我一个错误:子表达式不能用于nameof的参数中
如何访问嵌套类中的FirstName属性?