Skip to content

Commit d493349

Browse files
committed
Prevent creating objects with duplicated GUIDs
1 parent 766b9ac commit d493349

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/SIL.LCModel/LcmGenerate/factory.vm.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ internal partial class ${className}$classSfx : I${className}$classSfx, ILcmFacto
6464
if (m_cache.ServiceLocator.GetInstance<I${className}Repository>().Singleton != null)
6565
throw new InvalidOperationException("Can not create more than one ${className}");
6666
#end
67-
if (guid == Guid.Empty) guid = Guid.NewGuid();
67+
if (guid == Guid.Empty)
68+
{
69+
guid = Guid.NewGuid();
70+
}
71+
else
72+
{
73+
if (m_cache.ServiceLocator.GetInstance<I${className}Repository>()).TryGetObject(guid, out var _originalObject)
74+
{
75+
throw new InvalidOperationException("Can not create more than one ${className} with identical GUIDs");
76+
}
77+
}
6878
int hvo = m_cache.InternalServices.DataReader.GetNextRealHvo();
6979
var newby = new $className(m_cache, hvo, guid);
7080
#if ( $ownerStatus != "required")

0 commit comments

Comments
 (0)