呃,我该如何解释这个……可能是一个简单的问题,但我的头脑很混乱。
假设我有这样的课程:
public class NestedObject
{
public string NestedName { get; set; }
public int NestedIntValue { get; set; }
public decimal NestedDecimalValue { get; set; }
}
public class SomeBigExternalDTO
{
public int Id { get; set; }
public int UserId { get; set; }
public int SomeIntValue { get; set; }
public long SomeLongValue { get; set; }
public decimal SomeDecimalValue { get; set; }
public string SomeStringValue { get; set; }
public NestedObject SomeNestedObject { get; set; }
// ... thousands more of these properties... inherited code
}
我想要填充的类在这里:
public class MyResult
{
public int UserId { get; set; } // user id from above object
public string ResultValue { get; set; } // one of the value fields from above with .ToString() executed on it
}
我想做的是创建一个助手来返回该对象列表中所有实例的属性值(我猜横截面是我描述它的最佳方式):
var foo = new List<SomeBigExternalDTO>();
foo = GetMyListOfSomeBigExternalDTO();
public static List<MyResult> AwesomeHelper(List<SomeBigExternalDTO> input, SearchableProperty thePropertyIWant)
{
// some magic needs to happen here...
}
这里棘手的部分是我想根据链接选择器动态传递属性(我不知道如何做到这一点):
var output = AwesomeHelper(GetMyListOfSomeBigExternalDTO(), x => x.SomeIntValue);
var output2 = AwesomeHelper(GetMyListOfSomeBigExternalDTO(), x => x.SomeNestedObject.NestedIntValue);
这应该返回一个 MyResult 对象列表,其中 UserId 和 SomeIntValue.ToString() 对应于输入列表中的每个项目。
哇,我真的希望这是有道理的。如果不清楚,请告诉我,我将提供更多详细信息。我真的希望这是我忽略的图书馆中的一些东西。
关于我能完成这个任务有什么想法吗?