으음, 어떻게 설명할까요? 아마도 간단한 질문이지만 마음이 튀었을 것입니다. 여기.NET에서 입력 된 객체 목록에서 객체 속성의 모든 값을 선택하는 방법 C#
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의 목록을 반환해야한다는 사용자 아이디와 객체 및 SomeIntValue.ToString() 입력 목록의 각 항목에 해당합니다.
와우, 나는 이것이 정말로 의미가 있기를 바랍니다. 이것이 명확하지 않으면 알려주십시오. 자세한 내용을 알려 드리겠습니다. 나는 이것이 내가 간과 한 도서관에 구워진 것이기를 정말로 바라고 있습니다.
나는 이것을 달성하기위한 아이디어가 있습니까?
는
답변 해 주셔서 감사합니다. 내 후속 질문을 확인하십시오 : http://stackoverflow.com/questions/7396781/architecturally-speaking-how-should-i-replace-an-extremely-large-switch-statemen – longda