나는 약간의 규칙으로 으로 변환하고 (object value)
을 취하는 방법이 있습니다.IEnumerable <object> from IEnumrable <T>
이러한 규칙 중 하나는 값이 IEnumerable
일 때 관련이 있습니다. 이 경우 내가 열거의 각 항목을 처리 할 필요가 : 물론
public string Convert(object value)
{
var valuetype = value.GetType();
if (valuetype.GetInterface("IList") != null)
{
var e = (IEnumerable<object>) value;
return e.Count() == 0 ?
"" :
e.Select(o=>Convert(o)).Aggregate("", (c, s) => c+s);
}
}
, 값은 예를 들어, List<string>
경우, 라인
var e = (IEnumerable<object>) value;
예외
Unable to cast object of type 'System.Collections.Generic.List`1[System.String]' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.
어떤 아이디어라도 어떻게 없앨 수 있습니까?
컬렉션의 각 항목을 의미합니까? – msarchet
문자열에 함께 참여하고 있습니까? –
4보다 오래된 .net 버전을 사용하고 있습니까? – CodesInChaos