Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings in .NET Framework specific code #1323

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/Stripe.net/Infrastructure/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
Expand All @@ -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
Expand All @@ -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
}
}