【发布时间】:2014-06-16 11:45:31
【问题描述】:
所以.. 我有一些 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 是一个数组,并且“blah 中的元素类型”不工作,因为我现在不知道对象的类型。 ...
任何人有任何指导?
【问题讨论】:
-
您可以继续使用反射和调用 MapCollection 方法:stackoverflow.com/questions/232535/…。
-
好主意..但我仍然需要将集合作为 IQueryable
返回...有什么提示吗?
标签: c# wcf reflection automapper system.reflection