我还没有TRootEntity
时如何调用下面的方法, 但只有它的 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));
});
用于创建动态NHibernate HBM
.更多信息可用here
最佳答案
您不能通过传递运行时类型来编写要运行的通用方法。
泛型需要在编译时有类型。
您可能需要使用反射(参见 Ferreira 先生关于如何做到这一点的回答)。
关于c# - 将类型传递给泛型方法(嵌套泛型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6562685/