/// <summary> /// Get the reference id based on the tracked objects hashCode /// </summary> /// <param name="hashCode">The object's hashcode</param> /// <param name="type">The object's type</param> /// <returns></returns> public ushort GetObjectReferenceId(int hashCode, Type type) { var key = new ObjectKey(hashCode, type.GetHashCode()); var reference = _objectTree[key]; if (reference.Object.GetType() == type) { return(reference.ReferenceId); } throw new InvalidOperationException($"Hashcode '{hashCode}' and type '{type.Name}' not found."); }
/// <summary> /// Get an object from a tracked hashcode /// </summary> /// <param name="hashCode"></param> /// <returns></returns> public object GetObject(int hashCode, Type type) { var key = new ObjectKey(hashCode, type.GetHashCode()); var reference = _objectTree[key]; if (reference.Object.GetType() == type) { return(reference.Object); } return(null); }
/// <summary> /// True if the tracker is tracking the hashcode /// </summary> /// <param name="hashCode"></param> /// <returns></returns> public bool ContainsHashcode(int hashCode, Type type) { var key = new ObjectKey(hashCode, type.GetHashCode()); var containsKey = _objectTree.ContainsKey(key); if (containsKey) { var reference = _objectTree[key]; return(reference.Object.GetType() == type); } return(false); }