In MDriven I'd like to get the type discriminator for a modeled class at runtime. I thought I had done it before, but can't seem to find it and can't figure it out.
I mean the integer that appears first in the external id string, e.g. "72" in external id "72!i64!12345678".
I need to get the discriminator based on C# type, i.e. typeof(MyClass), without having any object instance available. This makes it impossible to extract the discriminator from the external id string, because I have no such string available at the time and can't create one.
I'm using Eco.Services.Impl.ExternalIdServiceImpl_DbType so the external id's type discriminator matches the type discriminator in the database, in case that matters. But how do I lookup the discriminator for a type, in runtime?
After finding source code for
Eco.Services.Impl.ExternalIdServiceImpl_DbTypeI was able to create this solution:The
sp.GetEcoService<IExternalIdService>() is Eco.Services.Impl.ExternalIdServiceImpl_DbTypeis required in my case, because in my unit tests i usePersistenceMapperMemory, which uses the index inTypeSystem.AllClassesas type discriminator, which is also the value returned byIClass.InternalIndex.I also note that
IExternalIdService.ObjectForIdSeperateClassInfo()is buggy. It acts as ifEco.Services.Impl.ExternalIdServiceImplis being used, returning anIObjectInstanceof the wrong type (using the class' index inTypeSystem.AllClasses).