From 7e02310a8ea9c24607a88718ee10ac5f85836fdb Mon Sep 17 00:00:00 2001 From: Entoarox Date: Mon, 23 Oct 2017 18:15:18 +0200 Subject: 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. --- src/SMAPI/Framework/Reflection/PrivateProperty.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/SMAPI/Framework/Reflection/PrivateProperty.cs') 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 /// The display name shown in error messages. private string DisplayName => $"{this.ParentType.FullName}::{this.PropertyInfo.Name}"; - private readonly Func GetterDelegate; - private readonly Action SetterDelegate; + private readonly Func GetterDelegate; + private readonly Action SetterDelegate; /********* @@ -53,8 +53,8 @@ namespace StardewModdingAPI.Framework.Reflection Type[] types = new Type[] { this.PropertyInfo.DeclaringType, typeof(TValue)}; - this.GetterDelegate = (Func)Delegate.CreateDelegate(typeof(Func<,>).MakeGenericType(types), this.PropertyInfo.GetMethod); - this.SetterDelegate = (Action)Delegate.CreateDelegate(typeof(Action<,>).MakeGenericType(types), this.PropertyInfo.SetMethod); + this.GetterDelegate = (Func)Delegate.CreateDelegate(typeof(Func), obj, this.PropertyInfo.GetMethod); + this.SetterDelegate = (Action)Delegate.CreateDelegate(typeof(Action), obj, this.PropertyInfo.SetMethod); } /// Get the property value. @@ -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); } -- cgit