1 //------------------------------------------------------------------------------
2 // <copyright file="BinaryCompatibility.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.Util {
8     using System;
9     using System.Runtime.Versioning;
10 
11     // This class contains utility methods that mimic the mscorlib internal System.Runtime.Versioning.BinaryCompatibility type.
12 
13     internal sealed class BinaryCompatibility {
14 
15         // We need to use this AppDomain key instead of AppDomainSetup.TargetFrameworkName since we don't want applications
16         // which happened to set TargetFrameworkName and are calling into ASP.NET APIs to suddenly start getting new behaviors.
17         internal const string TargetFrameworkKey = "ASPNET_TARGETFRAMEWORK";
18 
19         // quick accessor for the current AppDomain's instance
20         public static readonly BinaryCompatibility Current;
21 
BinaryCompatibility()22         static BinaryCompatibility() {
23             Current = new BinaryCompatibility(AppDomain.CurrentDomain.GetData(TargetFrameworkKey) as FrameworkName);
24 
25             TelemetryLogger.LogTargetFramework(Current.TargetFramework);
26         }
27 
BinaryCompatibility(FrameworkName frameworkName)28         public BinaryCompatibility(FrameworkName frameworkName) {
29             // parse version from FrameworkName, otherwise use a default value
30             Version version = VersionUtil.FrameworkDefault;
31             if (frameworkName != null && frameworkName.Identifier == ".NETFramework") {
32                 version = frameworkName.Version;
33             }
34 
35             TargetFramework = version;
36             TargetsAtLeastFramework45 = (version >= VersionUtil.Framework45);
37             TargetsAtLeastFramework451 = (version >= VersionUtil.Framework451);
38             TargetsAtLeastFramework452 = (version >= VersionUtil.Framework452);
39             TargetsAtLeastFramework46 = (version >= VersionUtil.Framework46);
40             TargetsAtLeastFramework461 = (version >= VersionUtil.Framework461);
41             TargetsAtLeastFramework463 = (version >= VersionUtil.Framework463);
42         }
43 
44         public bool TargetsAtLeastFramework45 { get; private set; }
45         public bool TargetsAtLeastFramework451 { get; private set; }
46         public bool TargetsAtLeastFramework452 { get; private set; }
47         public bool TargetsAtLeastFramework46 { get; private set; }
48         public bool TargetsAtLeastFramework461 { get; private set; }
49         public bool TargetsAtLeastFramework463 { get; private set; }
50 
51         public Version TargetFramework { get; private set; }
52 
53     }
54 }
55