Fix empty cache get

Fixed exception in DatabaseCache when attempting to get entry types which haven't been added
This commit is contained in:
hyperion51 2020-03-27 16:46:46 +00:00
commit 1a1b72105e

View file

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -66,6 +67,8 @@ public class DatabaseCache
public T Get<T>(Guid guid) where T : DatabaseEntry
{
if (!_types.ContainsKey(typeof(T)))
return null;
DatabaseEntry entry;
_types[typeof(T)].TryGetValue(guid, out entry);
return (T) entry;
@ -73,7 +76,7 @@ public class DatabaseCache
public IEnumerable<T> GetAll<T>()
{
return _types[typeof(T)].Values.Cast<T>();
return !_types.ContainsKey(typeof(T)) ? Enumerable.Empty<T>() : _types[typeof(T)].Values.Cast<T>();
}
public void Delete(DatabaseEntry entry, bool remote = false)