Fix empty cache get
Fixed exception in DatabaseCache when attempting to get entry types which haven't been added
This commit is contained in:
parent
60e87fb4f5
commit
1a1b72105e
1 changed files with 4 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue