그래서 .. 일부 WCF 서비스가 있고 이러한 wcf 서비스는 리플렉션으로 호출됩니다. 호출 된 각 서비스마다 다른 객체로 배열을 반환합니다.반사, 개체 컬렉션을 가져 와서 원하는 개체 형식으로 변환하십시오.
내 임무는 이러한 개체를 가져 와서 내 BusinessObjects에있는 개체에 매핑하는 것입니다. 그들은 T
에 의해 정의됩니다.
public virtual IQueryable<T> GetAll()
{
//Methods retreives an array of objects.
var blah = _getAllFromWcf.Invoke(_rawServiceObject, new object[] {});
//Says that this is an array
var blahsType = blah.GetType();
//This is the type of object in the array
var blahsElementType = blahsType.GetElementType();
//This is where i want to convert the element in the array to the type T so that i can return it in the IQueryable<T>
blah.MapCollection<'The type of element in blah', T>();
return null;
}
blah.MapCollection <는> AutoMapper을 사용하여리스트 내의 요소 변환 내가 만든 확장 방법.
MapCollection은 당연히 작동하지 않습니다. 왜냐하면이 시점에서 객체의 유형을 알지 못하기 때문에 blah가 배열이고 '쉼표로 요소 유형'이 작동하지 않는다는 것을 이해하지 못하기 때문입니다. ....
누구든지 지침이 있습니까?
리플렉션 및 Invoke MapCollection 메서드를 계속 사용할 수 있습니다. http://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method. – qbik
좋은 생각 ..하지만 여전히 IQueryable로 컬렉션을 반환해야합니다 ... 그 어떤 힌트? –