diff --git a/DesktopToast/ToastManager.cs b/DesktopToast/ToastManager.cs index feb9b20..47ce092 100644 --- a/DesktopToast/ToastManager.cs +++ b/DesktopToast/ToastManager.cs @@ -51,7 +51,7 @@ public static async Task ShowAsync(string requestJson) ToastRequest request; try { - request = new ToastRequest(requestJson); + request = ToastRequest.FromJsonString(requestJson); } catch { diff --git a/DesktopToast/ToastRequest.cs b/DesktopToast/ToastRequest.cs index 4ededbb..8279469 100644 --- a/DesktopToast/ToastRequest.cs +++ b/DesktopToast/ToastRequest.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Text; @@ -172,38 +171,29 @@ public string ShortcutIconFilePath public ToastRequest() { } - internal ToastRequest(string requestJson) : this() - { - Import(requestJson); - } - #endregion #region Import/Export /// - /// Imports from a request in JSON format. + /// Creates a toast request from a JSON string. /// /// Request in JSON format - internal void Import(string requestJson) + /// Toast request + public static ToastRequest FromJsonString(string requestJson) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(requestJson))) { var serializer = new DataContractJsonSerializer(typeof(ToastRequest)); - var buff = (ToastRequest)serializer.ReadObject(stream); - - typeof(ToastRequest).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) - .Where(x => x.CanWrite) - .ToList() - .ForEach(x => x.SetValue(this, x.GetValue(buff))); + return (ToastRequest)serializer.ReadObject(stream); } } /// - /// Exports a request in JSON format. + /// Converts the request to a JSON string. /// /// Request in JSON format - internal string Export() + public string ToJsonString() { using (var stream = new MemoryStream()) {