diff options
Diffstat (limited to 'src/SMAPI/Framework/Reflection/ReflectedField.cs')
-rw-r--r-- | src/SMAPI/Framework/Reflection/ReflectedField.cs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/SMAPI/Framework/Reflection/ReflectedField.cs b/src/SMAPI/Framework/Reflection/ReflectedField.cs index 921876b9..197a246e 100644 --- a/src/SMAPI/Framework/Reflection/ReflectedField.cs +++ b/src/SMAPI/Framework/Reflection/ReflectedField.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Reflection; @@ -15,8 +13,8 @@ namespace StardewModdingAPI.Framework.Reflection /// <summary>The type that has the field.</summary> private readonly Type ParentType; - /// <summary>The object that has the instance field (if applicable).</summary> - private readonly object Parent; + /// <summary>The object that has the instance field, or <c>null</c> for a static field.</summary> + private readonly object? Parent; /// <summary>The display name shown in error messages.</summary> private string DisplayName => $"{this.ParentType.FullName}::{this.FieldInfo.Name}"; @@ -34,12 +32,12 @@ namespace StardewModdingAPI.Framework.Reflection *********/ /// <summary>Construct an instance.</summary> /// <param name="parentType">The type that has the field.</param> - /// <param name="obj">The object that has the instance field (if applicable).</param> + /// <param name="obj">The object that has the instance field, or <c>null</c> for a static field.</param> /// <param name="field">The reflection metadata.</param> /// <param name="isStatic">Whether the field is static.</param> /// <exception cref="ArgumentNullException">The <paramref name="parentType"/> or <paramref name="field"/> is null.</exception> /// <exception cref="ArgumentException">The <paramref name="obj"/> is null for a non-static field, or not null for a static field.</exception> - public ReflectedField(Type parentType, object obj, FieldInfo field, bool isStatic) + public ReflectedField(Type parentType, object? obj, FieldInfo field, bool isStatic) { // validate if (parentType == null) @@ -58,11 +56,11 @@ namespace StardewModdingAPI.Framework.Reflection } /// <inheritdoc /> - public TValue GetValue() + public TValue? GetValue() { try { - return (TValue)this.FieldInfo.GetValue(this.Parent); + return (TValue?)this.FieldInfo.GetValue(this.Parent); } catch (InvalidCastException) { @@ -75,7 +73,7 @@ namespace StardewModdingAPI.Framework.Reflection } /// <inheritdoc /> - public void SetValue(TValue value) + public void SetValue(TValue? value) { try { |