/// <summary> /// Adds the given object to the object store, and returns its handle name (name:version). /// Throws exceptions if anything goes wrong. /// </summary> /// <typeparam name="T">Type of the object to add</typeparam> /// <param name="HandleName">Name under which the object shall be stored</param> /// <param name="obj">The object which shall be stored</param> /// <param name="storedObject">[out] the stored object</param> /// <returns>The Handle (name:version) under which the object was stored</returns> private static string AddOrUpdateInStoreOrThrow <T>(string HandleName, T obj, out IStoredObject <T> storedObject, Action OnUnregister = null) where T : class { // Remove any invalid parts from the input HandleName = HandleNames.GetNameFrom(HandleName); if (String.IsNullOrWhiteSpace(HandleName)) { throw new ArgumentException($"Invalid Handle name {HandleName}", nameof(HandleName)); } if (!m_ObjectStore.AddOrUpdate <T>(HandleName, obj, out storedObject, OnUnregister)) { throw new Exception("Could not add script to the object store"); } return(HandleNames.ToHandle(storedObject)); }