通过类型泛型方法(嵌套通用) [英] Pass type to generic method (nested generic)
问题描述
如何我调用下面的方法,而我还没有 TRootEntity
,但只是其键入
:
最终目标是下面的代码运行 它是用来创建动态NHibernate的 您不能编写泛型方法传递一个运行时类型来运行。 泛型需要在编译时的类型。 您可能需要使用反射(见先生的答案。费雷拉,关于如何做到这一点点)。 How can I invoke following method while I have not final goal is to run following code It is used to create dynamic NHibernate As related question see here and here. You cannot code Generic methods to run by passing a runtime Type. Generics need to have the type at compile time. You may need to use reflection (see answer of mr. Ferreira that point on how to do that). 这篇关于通过类型泛型方法(嵌套通用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! >
VAR映射器=新ModelMapper() ;
mapper.Class< MyClass的>(CA =>
{
ca.Id(X => x.Id,地图=>
{
图.Column(MyClassId);
map.Generator(Generators.HighLow,GMAP => gmap.Params(新{max_low = 100}));
});
约物业(X => x.Something,地图= GT; map.Length(150));
});
HBM
。更多信息可这里
TRootEntity
, but have just its TYPE
:public void Class<TRootEntity>(Action<IClassMapper<TRootEntity>> customizeAction) where TRootEntity : class;
var mapper = new ModelMapper();
mapper.Class<MyClass>(ca =>
{
ca.Id(x => x.Id, map =>
{
map.Column("MyClassId");
map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
});
ca.Property(x => x.Something, map => map.Length(150));
});
HBM
. More info available here