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