Use fancy C# 8 Nullable Reference pattern.
This commit is contained in:
@@ -6,13 +6,13 @@ namespace PkmnLibSharp.Library.Items
|
||||
{
|
||||
public class Item : PointerWrapper
|
||||
{
|
||||
private string _name;
|
||||
private string? _name;
|
||||
|
||||
internal Item(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name => _name ??= Creaturelib.Generated.Item.GetName(Ptr).PtrString();
|
||||
public string Name => _name ??= Creaturelib.Generated.Item.GetName(Ptr).PtrString()!;
|
||||
public ItemCategory Category => (ItemCategory) Creaturelib.Generated.Item.GetCategory(Ptr);
|
||||
|
||||
public BattleItemCategory BattleCategory =>
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace PkmnLibSharp.Library.Items
|
||||
_cache.Remove(key);
|
||||
}
|
||||
|
||||
public bool TryGet(string key, out Item item)
|
||||
public bool TryGet(string key, out Item? item)
|
||||
{
|
||||
if (_cache.TryGetValue(key, out item))
|
||||
return true;
|
||||
@@ -41,7 +41,7 @@ namespace PkmnLibSharp.Library.Items
|
||||
return false;
|
||||
if (TryResolvePointer(ptr, out item))
|
||||
{
|
||||
_cache.Add(key, item);
|
||||
_cache.Add(key, item!);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ namespace PkmnLibSharp.Library.Items
|
||||
return item;
|
||||
var ptr = IntPtr.Zero;
|
||||
Creaturelib.Generated.ItemLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
||||
if (TryResolvePointer(ptr, out item))
|
||||
if (TryResolvePointer(ptr, out Item? i))
|
||||
{
|
||||
_cache.Add(key, item);
|
||||
return item;
|
||||
_cache.Add(key, i!);
|
||||
return i!;
|
||||
}
|
||||
|
||||
item = new Item(ptr);
|
||||
|
||||
Reference in New Issue
Block a user