diff options
author | Entoarox <kvdk@kvdk.net> | 2017-10-23 18:15:18 +0200 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-24 20:18:23 -0400 |
commit | 7e02310a8ea9c24607a88718ee10ac5f85836fdb (patch) | |
tree | 9b85ec29595caf4310519895af4fb825bed7ffec /src/SMAPI/Framework/Reflection/PrivateProperty.cs | |
parent | 191d65f8d9e90cc3a9788afcae852f8879962428 (diff) | |
download | SMAPI-7e02310a8ea9c24607a88718ee10ac5f85836fdb.tar.gz SMAPI-7e02310a8ea9c24607a88718ee10ac5f85836fdb.tar.bz2 SMAPI-7e02310a8ea9c24607a88718ee10ac5f85836fdb.zip |
Fix object cast being needed - use closed instead of open delegate
The API does not allow the user to modify the `this` after the fact anyhow, so it isnt needed.
Diffstat (limited to 'src/SMAPI/Framework/Reflection/PrivateProperty.cs')
-rw-r--r-- | src/SMAPI/Framework/Reflection/PrivateProperty.cs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/SMAPI/Framework/Reflection/PrivateProperty.cs b/src/SMAPI/Framework/Reflection/PrivateProperty.cs index 718594ee..0fa10601 100644 --- a/src/SMAPI/Framework/Reflection/PrivateProperty.cs +++ b/src/SMAPI/Framework/Reflection/PrivateProperty.cs @@ -19,8 +19,8 @@ namespace StardewModdingAPI.Framework.Reflection /// <summary>The display name shown in error messages.</summary> private string DisplayName => $"{this.ParentType.FullName}::{this.PropertyInfo.Name}"; - private readonly Func<object, TValue> GetterDelegate; - private readonly Action<object, TValue> SetterDelegate; + private readonly Func<TValue> GetterDelegate; + private readonly Action<TValue> SetterDelegate; /********* @@ -53,8 +53,8 @@ namespace StardewModdingAPI.Framework.Reflection Type[] types = new Type[] { this.PropertyInfo.DeclaringType, typeof(TValue)}; - this.GetterDelegate = (Func<object, TValue>)Delegate.CreateDelegate(typeof(Func<,>).MakeGenericType(types), this.PropertyInfo.GetMethod); - this.SetterDelegate = (Action<object, TValue>)Delegate.CreateDelegate(typeof(Action<,>).MakeGenericType(types), this.PropertyInfo.SetMethod); + this.GetterDelegate = (Func<TValue>)Delegate.CreateDelegate(typeof(Func<TValue>), obj, this.PropertyInfo.GetMethod); + this.SetterDelegate = (Action<TValue>)Delegate.CreateDelegate(typeof(Action<TValue>), obj, this.PropertyInfo.SetMethod); } /// <summary>Get the property value.</summary> @@ -62,7 +62,7 @@ namespace StardewModdingAPI.Framework.Reflection { try { - return this.GetterDelegate(this.Parent); + return this.GetterDelegate(); // Old version: Commented out in case of issues with new version //return (TValue)this.PropertyInfo.GetValue(this.Parent); } @@ -82,7 +82,7 @@ namespace StardewModdingAPI.Framework.Reflection { try { - this.SetterDelegate(this.Parent, value); + this.SetterDelegate(value); // Old version: Commented out in case of issues with new version //this.PropertyInfo.SetValue(this.Parent, value); } |