通用映射器调用另一个映射器
generic mapper call another mapper
在旧应用程序中,我使用单独的地图将任何模型转换为视图模型和逆模型。
现在我想使用通用函数,但通用函数不能直接调用 map
public class GenericBll<TVModel, TMModel> where TVModel : class where TMModel : class
{
public virtual IEnumerable<TVModel> GetAll()
{
var a = Instance.GetAll_asQuery().ToList();
var b = a.Select(q=> Mapper.Map<TVModel,TMModel>(q)).ToList();
//mapper not return true thing
return b;
}
}
这是我的通用映射器
public partial class Mapper
{
internal static TVModel Map<TMModel>(TMModel q) where TMModel : class where TVModel : class
{
//want to this function call another but always run this :(
throw new NotImplementedException();
}
public static MM.GroupDevides Map(GroupDevides e)
{
//map to MM.GroupDevides
}
public static GroupDevides Map(MM.GroupDevides e)
{
//map to GroupDevides
}
}
i,m 新的泛型请帮忙
我不确定你想做什么,但是如果你想调用 Mapper.Map(q) 其中 q 是某处的 GroupDevides 类型,它使用通用方法并传递参数转换到 TMModel。
如果要调用Mapper.Map(GroupDevides e),需要直接调用或者根据q的类型让Mapper.Map(q)调用。
代码看起来像这样:
class Mapper
{
public static object Map<TMModel>(TMModel q) where TMModel : class
{
MethodInfo methodInfo = typeof(Mapper).GetMethod("Map", new Type[] { q.GetType() });
if (methodInfo != null)
return methodInfo.Invoke(null, new object[] { q });
return null;
}
public static GroupDevides Map(MM.GroupDevides e)
{
//map to GroupDevides
}
}
在旧应用程序中,我使用单独的地图将任何模型转换为视图模型和逆模型。 现在我想使用通用函数,但通用函数不能直接调用 map
public class GenericBll<TVModel, TMModel> where TVModel : class where TMModel : class
{
public virtual IEnumerable<TVModel> GetAll()
{
var a = Instance.GetAll_asQuery().ToList();
var b = a.Select(q=> Mapper.Map<TVModel,TMModel>(q)).ToList();
//mapper not return true thing
return b;
}
}
这是我的通用映射器
public partial class Mapper
{
internal static TVModel Map<TMModel>(TMModel q) where TMModel : class where TVModel : class
{
//want to this function call another but always run this :(
throw new NotImplementedException();
}
public static MM.GroupDevides Map(GroupDevides e)
{
//map to MM.GroupDevides
}
public static GroupDevides Map(MM.GroupDevides e)
{
//map to GroupDevides
}
}
i,m 新的泛型请帮忙
我不确定你想做什么,但是如果你想调用 Mapper.Map(q) 其中 q 是某处的 GroupDevides 类型,它使用通用方法并传递参数转换到 TMModel。
如果要调用Mapper.Map(GroupDevides e),需要直接调用或者根据q的类型让Mapper.Map(q)调用。 代码看起来像这样:
class Mapper
{
public static object Map<TMModel>(TMModel q) where TMModel : class
{
MethodInfo methodInfo = typeof(Mapper).GetMethod("Map", new Type[] { q.GetType() });
if (methodInfo != null)
return methodInfo.Invoke(null, new object[] { q });
return null;
}
public static GroupDevides Map(MM.GroupDevides e)
{
//map to GroupDevides
}
}