diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-16 11:10:13 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-16 11:10:13 -0400 |
commit | 2dc20be5f711c50cc80de024c8a6afb96c04d8a1 (patch) | |
tree | 2b367f58c99ab63c313e3beda59b0bdab946c1a4 /src/SMAPI/Framework/Reflection | |
parent | c0d0ad0282169a829ffee4808088ebf434ba498d (diff) | |
download | SMAPI-2dc20be5f711c50cc80de024c8a6afb96c04d8a1.tar.gz SMAPI-2dc20be5f711c50cc80de024c8a6afb96c04d8a1.tar.bz2 SMAPI-2dc20be5f711c50cc80de024c8a6afb96c04d8a1.zip |
use specified nullability in reflection API (#837)
Diffstat (limited to 'src/SMAPI/Framework/Reflection')
-rw-r--r-- | src/SMAPI/Framework/Reflection/ReflectedField.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/Reflection/ReflectedMethod.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/Reflection/ReflectedProperty.cs | 12 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/SMAPI/Framework/Reflection/ReflectedField.cs b/src/SMAPI/Framework/Reflection/ReflectedField.cs index 197a246e..a97ca3f0 100644 --- a/src/SMAPI/Framework/Reflection/ReflectedField.cs +++ b/src/SMAPI/Framework/Reflection/ReflectedField.cs @@ -56,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) { @@ -73,7 +73,7 @@ namespace StardewModdingAPI.Framework.Reflection } /// <inheritdoc /> - public void SetValue(TValue? value) + public void SetValue(TValue value) { try { diff --git a/src/SMAPI/Framework/Reflection/ReflectedMethod.cs b/src/SMAPI/Framework/Reflection/ReflectedMethod.cs index c245e843..a607141e 100644 --- a/src/SMAPI/Framework/Reflection/ReflectedMethod.cs +++ b/src/SMAPI/Framework/Reflection/ReflectedMethod.cs @@ -55,7 +55,7 @@ namespace StardewModdingAPI.Framework.Reflection } /// <inheritdoc /> - public TValue? Invoke<TValue>(params object?[] arguments) + public TValue Invoke<TValue>(params object?[] arguments) { // invoke method object? result; @@ -75,7 +75,7 @@ namespace StardewModdingAPI.Framework.Reflection // cast return value try { - return (TValue?)result; + return (TValue)result!; } catch (InvalidCastException) { diff --git a/src/SMAPI/Framework/Reflection/ReflectedProperty.cs b/src/SMAPI/Framework/Reflection/ReflectedProperty.cs index 638953a3..72e701d1 100644 --- a/src/SMAPI/Framework/Reflection/ReflectedProperty.cs +++ b/src/SMAPI/Framework/Reflection/ReflectedProperty.cs @@ -14,10 +14,10 @@ namespace StardewModdingAPI.Framework.Reflection private readonly string DisplayName; /// <summary>The underlying property getter.</summary> - private readonly Func<TValue?>? GetMethod; + private readonly Func<TValue>? GetMethod; /// <summary>The underlying property setter.</summary> - private readonly Action<TValue?>? SetMethod; + private readonly Action<TValue>? SetMethod; /********* @@ -56,13 +56,13 @@ namespace StardewModdingAPI.Framework.Reflection this.PropertyInfo = property; if (this.PropertyInfo.GetMethod != null) - this.GetMethod = (Func<TValue?>)Delegate.CreateDelegate(typeof(Func<TValue?>), obj, this.PropertyInfo.GetMethod); + this.GetMethod = (Func<TValue>)Delegate.CreateDelegate(typeof(Func<TValue>), obj, this.PropertyInfo.GetMethod); if (this.PropertyInfo.SetMethod != null) - this.SetMethod = (Action<TValue?>)Delegate.CreateDelegate(typeof(Action<TValue?>), obj, this.PropertyInfo.SetMethod); + this.SetMethod = (Action<TValue>)Delegate.CreateDelegate(typeof(Action<TValue>), obj, this.PropertyInfo.SetMethod); } /// <inheritdoc /> - public TValue? GetValue() + public TValue GetValue() { if (this.GetMethod == null) throw new InvalidOperationException($"The {this.DisplayName} property has no get method."); @@ -82,7 +82,7 @@ namespace StardewModdingAPI.Framework.Reflection } /// <inheritdoc /> - public void SetValue(TValue? value) + public void SetValue(TValue value) { if (this.SetMethod == null) throw new InvalidOperationException($"The {this.DisplayName} property has no set method."); |