diff --git a/LibreMetaverse/Inventory.cs b/LibreMetaverse/Inventory.cs index 8f197b6d..9378486e 100644 --- a/LibreMetaverse/Inventory.cs +++ b/LibreMetaverse/Inventory.cs @@ -360,6 +360,53 @@ namespace OpenMetaverse return Items.ContainsKey(uuid); } + /// + /// Attempts to retrieve an item associated with the specified UUID. + /// This method is a specialized overload for retrieving items of type or its derived types. + /// + /// The unique identifier of the item to retrieve. + /// When this method returns true, contains the item if found; otherwise, null. + /// true if an item with the specified UUID was found; otherwise, false. + /// + /// Use this method when you specifically need an item without casting from a generic type. + /// For retrieving items of other types, use the generic method. + /// + public bool TryGetValue(UUID uuid, out InventoryBase item) + { + item = null; + + if(TryGetNodeFor(uuid, out var node)) + { + item = node.Data; + } + + return item != null; + } + + /// + /// Attempts to retrieve an item of type associated with the specified UUID. + /// This method is generic and can be used for any type stored in the inventory. + /// + /// The type of the item to retrieve. + /// The unique identifier of the item to retrieve. + /// When this method returns, contains the item of type if found and compatible with the requested type; otherwise, the default value of . + /// true if an item with the specified UUID was found and is of type ; otherwise, false. + /// + /// Use this method when you need to retrieve an item of a specific type other than . + /// If you are retrieving an item or its derived types, consider using the specialized overload for convenience. + /// + public bool TryGetValue(UUID uuid, out T item) + { + if (TryGetNodeFor(uuid, out var node) && node.Data is T requestedItem) + { + item = requestedItem; + return true; + } + + item = default; + return false; + } + /// /// Check that Inventory contains the InventoryObject specified by . ///