/// <summary> /// Retrieves an unpacked asset instance. /// </summary> /// <typeparam name="TValue">Asset type.</typeparam> /// <param name="consumer">Consumer reference for the access request.</param> /// <param name="key">Key used for retrieval.</param> /// <returns>An unpacked asset.</returns> public static TValue Get <TValue>(IAssetConsumer consumer, dynamic key) { if (LookupDictionary.ContainsKey(typeof(Asset <TValue>))) { return(LookupDictionary[typeof(Asset <TValue>)].Get(consumer, key)); } throw new KeyNotFoundException("No asset for the specified key was found."); }
public static Dictionary <string, TValue> GetDictionary <TValue>(IAssetConsumer consumer) { if (LookupDictionary.ContainsKey(typeof(Asset <TValue>))) { return(LookupDictionary[(dynamic)typeof(Asset <TValue>)].GetData(consumer)); } return(null); }
public bool TryGet(IAssetConsumer consumer, string key, out TValue value) { value = default; if (data.TryGetValue(key, out Asset <TValue> asset)) { value = asset.Get(consumer); return(true); } return(false); }
public Dictionary <string, TValue> GetData(IAssetConsumer consumer) { Dictionary <string, TValue> dict = new Dictionary <string, TValue>(); foreach ((string key, Asset <TValue> value) in data) { dict.Add(key, value.Get(consumer)); } return(dict); }
/// <summary> /// Attempts to return an unpacked asset instance. /// </summary> /// <typeparam name="TKey">Key type.</typeparam> /// <typeparam name="TValue">Asset type.</typeparam> /// <param name="consumer">Consumer reference for the access request.</param> /// <param name="key">Key used for retrieval.</param> /// <param name="value">Array resource returned.</param> /// <returns>True if successful.</returns> public static bool TryGet <TValue>(IAssetConsumer consumer, string key, out dynamic value) => LookupDictionary[typeof(Asset <TValue>)].TryGet(consumer, key, out value);
public TValue Get(IAssetConsumer consumer, string key) => data.TryGetValue(key, out Asset <TValue> asset) ? asset.Get(consumer) : default;