var type = data.ClientBaseObject.GetType();
var newClientObject = GetDataContextedObject(type, data.ClientBaseObject);
private object GetDataContextedObject(Type type, object jobObject)
{
switch (type.Name.ToUpper())
{
case "JOBNUMBER":
{
return GetObjectFromDataContext<JobNumber>(jobObject);
}
case "NA_HEADER":
{
return GetObjectFromDataContext<NA_Header>(jobObject);
}
}
return null;
}
private object GetObjectFromDataContext<T>(object jobObject) where T: class, IJobID
{
var newObject = jobObject as T;
return _dc.GetTable<T>().FirstOrDefault(j => j.JobID == newObject.JobID);
}
在上面的代码中,我想知道是否有一种方法可以使GetObjectFromDataContext
into GetObjectFromDataContext<type>
,而不必为每个类获取 type.Name 并为每个类创建一个案例。这可以做到吗?
如果问题不清楚,请告诉我。