public CdmObjectBase(CdmCorpusContext ctx) { if (ctx?.Corpus != null) { // when loading imports asynchronously, multiple objects may be created at the same time so multiple objects // can inadvertently get the same ID. Adding a lock here ensures that the global id variable is incremented // and then that value is set to the object ID before that same process can happen for another object bool lockTaken = false; try { // acquire spinlock ctx.Corpus.spinLock.Enter(ref lockTaken); this.Id = CdmCorpusDefinition.NextId(); } finally { // release spinlock if (lockTaken) { ctx.Corpus.spinLock.Exit(); } } } this.Ctx = ctx; }
public CdmObjectBase(CdmCorpusContext ctx) { this.Id = CdmCorpusDefinition.NextId(); this.Ctx = ctx; if (ctx != null) { this.DocCreatedIn = (ctx as ResolveContext).CurrentDoc; } }
public CdmObjectBase(CdmCorpusContext ctx) { this.Id = CdmCorpusDefinition.NextId(); this.Ctx = ctx; }