From 9c97b78f8ba796e2aca1fefb63284c32726713a4 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Fri, 5 Oct 2018 21:48:23 +0200 Subject: [PATCH] Fix warning in .NET Framework specific code --- src/Stripe.net/Infrastructure/Client.cs | 42 +++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Stripe.net/Infrastructure/Client.cs b/src/Stripe.net/Infrastructure/Client.cs index 7c50d68898..ec26ca6dc7 100644 --- a/src/Stripe.net/Infrastructure/Client.cs +++ b/src/Stripe.net/Infrastructure/Client.cs @@ -31,6 +31,30 @@ public void ApplyClientData() this.RequestMessage.Headers.Add("X-Stripe-Client-User-Agent", this.GetClientUserAgentString()); } +#if NET45 + private static string GetMonoVersion() + { + Type monoRuntimeType = typeof(object).Assembly.GetType("Mono.Runtime"); + + if (monoRuntimeType != null) + { + MethodInfo getDisplayNameMethod = monoRuntimeType.GetMethod( + "GetDisplayName", + BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, + null, + Type.EmptyTypes, + null); + + if (getDisplayNameMethod != null) + { + return (string)getDisplayNameMethod.Invoke(null, null); + } + } + + return null; + } +#endif + private string GetClientUserAgentString() { var values = new Dictionary @@ -45,7 +69,8 @@ private string GetClientUserAgentString() values.Add("os_version", Environment.OSVersion.ToString()); string monoVersion = Client.GetMonoVersion(); - if (monoVersion != null) { + if (monoVersion != null) + { values.Add("mono_version", monoVersion); } #else @@ -55,20 +80,5 @@ private string GetClientUserAgentString() return JsonConvert.SerializeObject(values, Formatting.None); } - -#if NET45 - private static string GetMonoVersion() - { - Type monoRuntimeType; - MethodInfo getDisplayNameMethod; - if ((monoRuntimeType = typeof(object).Assembly.GetType("Mono.Runtime")) != null && - (getDisplayNameMethod = monoRuntimeType.GetMethod("GetDisplayName", - BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, - Type.EmptyTypes, null)) != null) { - return (string)getDisplayNameMethod.Invoke(null, null); - } - return null; - } -#endif } }