| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Reflection; |
| | 6 | | using System.Runtime.Versioning; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.ServiceBus.Primitives |
| | 9 | | { |
| | 10 | | internal static class ClientInfo |
| | 11 | | { |
| 0 | 12 | | internal static Assembly assembly = GetAssesmbly(); |
| 0 | 13 | | internal static readonly string Product = GetAssemblyAttributeValue<AssemblyProductAttribute>(assembly, p => p.P |
| 0 | 14 | | internal static readonly string Version = GetAssemblyAttributeValue<AssemblyFileVersionAttribute>(assembly, v => |
| 0 | 15 | | internal static readonly string Framework = GetAssemblyAttributeValue<TargetFrameworkAttribute>(assembly, f => f |
| | 16 | |
|
| 0 | 17 | | internal static readonly string Platform = GetPlatform(); |
| | 18 | |
|
| | 19 | | internal static string GetPlatform() |
| | 20 | | { |
| | 21 | | try |
| | 22 | | { |
| | 23 | | #if NETSTANDARD2_0 |
| 0 | 24 | | return System.Runtime.InteropServices.RuntimeInformation.OSDescription; |
| | 25 | | #elif UAP10_0 |
| | 26 | | return "UAP"; |
| | 27 | | #elif NET461 |
| | 28 | | return Environment.OSVersion.VersionString; |
| | 29 | | #else |
| | 30 | | return "Unknown"; |
| | 31 | | #endif |
| | 32 | | } |
| 0 | 33 | | catch |
| | 34 | | { |
| | 35 | | // ignored |
| 0 | 36 | | return null; |
| | 37 | | } |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | internal static Assembly GetAssesmbly() |
| | 41 | | { |
| 0 | 42 | | return typeof(ClientInfo).GetTypeInfo().Assembly; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | internal static string GetAssemblyAttributeValue<T>(Assembly assembly, Func<T, string> getter) where T : Attribu |
| | 46 | | { |
| 0 | 47 | | return !(assembly.GetCustomAttribute(typeof(T)) is T attribute) ? null : getter(attribute); |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |