问题描述
当我没有 TRootEntity
时,我如何调用以下方法,但只有其 TYPE
:
public void Class< TRootEntity>(Action< IClassMapper< TRootEntity>> customizeAction)其中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.属性(x => x.Something,map => map.Length(150));
});
它用于创建动态NHibernate HBM
。更多信息
相关问题请参阅和。
您不能通过传递运行时类型代码通用方法运行。 / p>
泛型需要在编译时具有类型。
您可能需要使用反射(请参阅mr的答案Ferreira指出如何做到这一点。)
How can I invoke following method while I have not TRootEntity
, but have just its TYPE
:
public void Class<TRootEntity>(Action<IClassMapper<TRootEntity>> customizeAction) where TRootEntity : class;
final goal is to run following code
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));
});
It is used to create dynamic NHibernate HBM
. More info available here
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).
这篇关于传递类型为通用方法(嵌套泛型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!