Reputation: 11483
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.
Upvotes: 8
Views: 42632
Reputation: 7342
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).
Upvotes: 16
Reputation:
Have a look at this answer from the great Jon Skeet. You should be able to adapt it to your needs.
Upvotes: 14