public void Add(RefCounted refCounted, RefType refType = RefType.REF_DEFAULT) { lock (knownObjects) { ReferenceHolder <RefCounted> knownObject; if (knownObjects.TryGetValue(refCounted.nativeInstance, out knownObject)) { var existingObj = knownObject?.Reference; // this is another check verifying correct RefCounted by using type, which isn't a good test if (existingObj != null && !IsInHierarchy(existingObj.GetType(), refCounted.GetType())) { throw new InvalidOperationException($"NativeInstance '{refCounted.nativeInstance}' is in use by '{existingObj.GetType().Name}' (IsDeleted={existingObj.nativeInstance == IntPtr.Zero}). {refCounted.GetType()}"); } } // first check if explicit strong reference bool strongRef = refType == RefType.REF_STRONG; if (!strongRef) { strongRef = StrongRefByDefault(refCounted); } knownObjects[refCounted.nativeInstance] = new ReferenceHolder <RefCounted>(refCounted, !strongRef); } }
static private void registerSubsystem(RefCounted subsystem) { subSystems[subsystem.GetType()] = subsystem; }