summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-14 18:16:44 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-14 18:16:44 -0400
commit307304a03edb82f3a1f5cfa6c47cb17687560ccb (patch)
treefdd46e84bac0d05e4eafdbb4f05d8c5c70507a7b /src/StardewModdingAPI/Framework
parent06871a0603fa59ca6734fd913e118a4fe4a4c64c (diff)
downloadSMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.tar.gz
SMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.tar.bz2
SMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.zip
revert all projects except installer to .NET Framework 4.5
This caused obscure invalid-IL crashes when compiled through MonoDevelop on Linux.
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs29
-rw-r--r--src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs4
-rw-r--r--src/StardewModdingAPI/Framework/UpdateHelper.cs7
3 files changed, 8 insertions, 32 deletions
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index 46c76656..4ca79518 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using StardewModdingAPI.Events;
namespace StardewModdingAPI.Framework
{
@@ -60,36 +59,12 @@ namespace StardewModdingAPI.Framework
/// <param name="handlers">The event handlers.</param>
/// <param name="sender">The event sender.</param>
/// <param name="args">The event arguments.</param>
- public static void SafelyRaiseGenericEvent<TEventArgs>(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, TEventArgs args) where TEventArgs : EventArgs
+ public static void SafelyRaiseGenericEvent<TEventArgs>(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, TEventArgs args)
{
if (handlers == null)
return;
- foreach (EventHandler<TEventArgs> handler in handlers.Cast<EventHandler<TEventArgs>>())
- {
- try
- {
- handler.Invoke(sender, args);
- }
- catch (Exception ex)
- {
- monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
- }
- }
- }
-
- /// <summary>Safely raise an <see cref="EventHandler{TEventArgs}"/> event, and intercept any exceptions thrown by its handlers.</summary>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- /// <param name="name">The event name for error messages.</param>
- /// <param name="handlers">The event handlers.</param>
- /// <param name="sender">The event sender.</param>
- /// <param name="args">The event arguments.</param>
- public static void SafelyRaiseGenericEvent(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, IContentEventHelper args)
- {
- if (handlers == null)
- return;
-
- foreach (ContentEventHandler handler in handlers.Cast<ContentEventHandler>())
+ foreach (EventHandler<TEventArgs> handler in Enumerable.Cast<EventHandler<TEventArgs>>(handlers))
{
try
{
diff --git a/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs b/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
index d89e8e44..08204b7e 100644
--- a/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
+++ b/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
@@ -60,7 +60,7 @@ namespace StardewModdingAPI.Framework.Reflection
{
try
{
- return (TValue)this.PropertyInfo.GetValue(this.Parent, null);
+ return (TValue)this.PropertyInfo.GetValue(this.Parent);
}
catch (InvalidCastException)
{
@@ -78,7 +78,7 @@ namespace StardewModdingAPI.Framework.Reflection
{
try
{
- this.PropertyInfo.SetValue(this.Parent, value, null);
+ this.PropertyInfo.SetValue(this.Parent, value);
}
catch (InvalidCastException)
{
diff --git a/src/StardewModdingAPI/Framework/UpdateHelper.cs b/src/StardewModdingAPI/Framework/UpdateHelper.cs
index 342a08cf..e01e55c8 100644
--- a/src/StardewModdingAPI/Framework/UpdateHelper.cs
+++ b/src/StardewModdingAPI/Framework/UpdateHelper.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Net;
using System.Reflection;
+using System.Threading.Tasks;
using Newtonsoft.Json;
using StardewModdingAPI.Framework.Models;
@@ -14,17 +15,17 @@ namespace StardewModdingAPI.Framework
*********/
/// <summary>Get the latest release from a GitHub repository.</summary>
/// <param name="repository">The name of the repository from which to fetch releases (like "cjsu/SMAPI").</param>
- public static GitRelease GetLatestVersion(string repository)
+ public static async Task<GitRelease> GetLatestVersionAsync(string repository)
{
// build request
// (avoid HttpClient for Mac compatibility)
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.github.com/repos/{repository}/releases/latest");
+ HttpWebRequest request = WebRequest.CreateHttp($"https://api.github.com/repos/{repository}/releases/latest");
AssemblyName assembly = typeof(UpdateHelper).Assembly.GetName();
request.UserAgent = $"{assembly.Name}/{assembly.Version}";
request.Accept = "application/vnd.github.v3+json";
// fetch data
- using (WebResponse response = request.GetResponse())
+ using (WebResponse response = await request.GetResponseAsync())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{