Skip to content

Instantly share code, notes, and snippets.

@agross
Created September 5, 2014 18:01
Show Gist options
  • Save agross/ad9618bcd9a9cc260eca to your computer and use it in GitHub Desktop.
Save agross/ad9618bcd9a9cc260eca to your computer and use it in GitHub Desktop.
// Decompiled with JetBrains decompiler
// Type: NuGet.VersionUtility
// Assembly: NuGet.Core, Version=2.8.50313.46, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 4404F95E-CF52-4857-811C-40FE351F2921
// Assembly location: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\i5o50bmq.ucl\NuGet.Core.dll
using NuGet.Resources;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
namespace NuGet
{
public static class VersionUtility
{
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "The type FrameworkName is immutable.")]
public static readonly FrameworkName EmptyFramework = new FrameworkName("NoFramework", new Version());
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "The type FrameworkName is immutable.")]
public static readonly FrameworkName NativeProjectFramework = new FrameworkName("Native", new Version());
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "The type FrameworkName is immutable.")]
public static readonly FrameworkName UnsupportedFrameworkName = new FrameworkName("Unsupported", new Version());
private static readonly Version _emptyVersion = new Version();
private const string NetFrameworkIdentifier = ".NETFramework";
private const string NetCoreFrameworkIdentifier = ".NETCore";
private const string PortableFrameworkIdentifier = ".NETPortable";
private const string LessThanOrEqualTo = "≤";
private const string GreaterThanOrEqualTo = "≥";
private static readonly Dictionary<string, string> _knownIdentifiers;
private static readonly Dictionary<string, string> _knownProfiles;
private static readonly Dictionary<string, string> _identifierToFrameworkFolder;
private static readonly Dictionary<string, string> _identifierToProfileFolder;
private static readonly Dictionary<string, Dictionary<string, string[]>> _compatibiltyMapping;
private static readonly Dictionary<FrameworkName, FrameworkName> _frameworkNameAlias;
public static Version DefaultTargetFrameworkVersion
{
get
{
return typeof (string).Assembly.GetName().Version;
}
}
public static FrameworkName DefaultTargetFramework
{
get
{
return new FrameworkName(".NETFramework", VersionUtility.DefaultTargetFrameworkVersion);
}
}
static VersionUtility()
{
Dictionary<string, string> dictionary1 = new Dictionary<string, string>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
string key1 = "NET";
string str1 = ".NETFramework";
dictionary1.Add(key1, str1);
string key2 = ".NET";
string str2 = ".NETFramework";
dictionary1.Add(key2, str2);
string key3 = "NETFramework";
string str3 = ".NETFramework";
dictionary1.Add(key3, str3);
string key4 = ".NETFramework";
string str4 = ".NETFramework";
dictionary1.Add(key4, str4);
string key5 = "NETCore";
string str5 = ".NETCore";
dictionary1.Add(key5, str5);
string key6 = ".NETCore";
string str6 = ".NETCore";
dictionary1.Add(key6, str6);
string key7 = "WinRT";
string str7 = ".NETCore";
dictionary1.Add(key7, str7);
string key8 = ".NETMicroFramework";
string str8 = ".NETMicroFramework";
dictionary1.Add(key8, str8);
string key9 = "netmf";
string str9 = ".NETMicroFramework";
dictionary1.Add(key9, str9);
string key10 = "SL";
string str10 = "Silverlight";
dictionary1.Add(key10, str10);
string key11 = "Silverlight";
string str11 = "Silverlight";
dictionary1.Add(key11, str11);
string key12 = ".NETPortable";
string str12 = ".NETPortable";
dictionary1.Add(key12, str12);
string key13 = "NETPortable";
string str13 = ".NETPortable";
dictionary1.Add(key13, str13);
string key14 = "portable";
string str14 = ".NETPortable";
dictionary1.Add(key14, str14);
string key15 = "wp";
string str15 = "WindowsPhone";
dictionary1.Add(key15, str15);
string key16 = "WindowsPhone";
string str16 = "WindowsPhone";
dictionary1.Add(key16, str16);
string key17 = "Windows";
string str17 = "Windows";
dictionary1.Add(key17, str17);
string key18 = "win";
string str18 = "Windows";
dictionary1.Add(key18, str18);
string key19 = "MonoAndroid";
string str19 = "MonoAndroid";
dictionary1.Add(key19, str19);
string key20 = "MonoTouch";
string str20 = "MonoTouch";
dictionary1.Add(key20, str20);
string key21 = "MonoMac";
string str21 = "MonoMac";
dictionary1.Add(key21, str21);
string key22 = "native";
string str22 = "native";
dictionary1.Add(key22, str22);
string key23 = "WindowsPhoneApp";
string str23 = "WindowsPhoneApp";
dictionary1.Add(key23, str23);
string key24 = "wpa";
string str24 = "WindowsPhoneApp";
dictionary1.Add(key24, str24);
VersionUtility._knownIdentifiers = dictionary1;
Dictionary<string, string> dictionary2 = new Dictionary<string, string>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
string key25 = "Client";
string str25 = "Client";
dictionary2.Add(key25, str25);
string key26 = "WP";
string str26 = "WindowsPhone";
dictionary2.Add(key26, str26);
string key27 = "WP71";
string str27 = "WindowsPhone71";
dictionary2.Add(key27, str27);
string key28 = "CF";
string str28 = "CompactFramework";
dictionary2.Add(key28, str28);
string key29 = "Full";
string str29 = string.Empty;
dictionary2.Add(key29, str29);
VersionUtility._knownProfiles = dictionary2;
Dictionary<string, string> dictionary3 = new Dictionary<string, string>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
string key30 = ".NETFramework";
string str30 = "net";
dictionary3.Add(key30, str30);
string key31 = ".NETMicroFramework";
string str31 = "netmf";
dictionary3.Add(key31, str31);
string key32 = "Silverlight";
string str32 = "sl";
dictionary3.Add(key32, str32);
string key33 = ".NETCore";
string str33 = "win";
dictionary3.Add(key33, str33);
string key34 = "Windows";
string str34 = "win";
dictionary3.Add(key34, str34);
string key35 = ".NETPortable";
string str35 = "portable";
dictionary3.Add(key35, str35);
string key36 = "WindowsPhone";
string str36 = "wp";
dictionary3.Add(key36, str36);
string key37 = "WindowsPhoneApp";
string str37 = "wpa";
dictionary3.Add(key37, str37);
VersionUtility._identifierToFrameworkFolder = dictionary3;
Dictionary<string, string> dictionary4 = new Dictionary<string, string>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
string key38 = "WindowsPhone";
string str38 = "wp";
dictionary4.Add(key38, str38);
string key39 = "WindowsPhone71";
string str39 = "wp71";
dictionary4.Add(key39, str39);
string key40 = "CompactFramework";
string str40 = "cf";
dictionary4.Add(key40, str40);
VersionUtility._identifierToProfileFolder = dictionary4;
Dictionary<string, Dictionary<string, string[]>> dictionary5 = new Dictionary<string, Dictionary<string, string[]>>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
Dictionary<string, Dictionary<string, string[]>> dictionary6 = dictionary5;
string key41 = ".NETFramework";
Dictionary<string, string[]> dictionary7 = new Dictionary<string, string[]>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
Dictionary<string, string[]> dictionary8 = dictionary7;
string key42 = "";
string[] strArray1 = new string[1];
int index1 = 0;
string str41 = "Client";
strArray1[index1] = str41;
dictionary8.Add(key42, strArray1);
Dictionary<string, string[]> dictionary9 = dictionary7;
string key43 = "Client";
string[] strArray2 = new string[1];
int index2 = 0;
string str42 = "";
strArray2[index2] = str42;
dictionary9.Add(key43, strArray2);
Dictionary<string, string[]> dictionary10 = dictionary7;
dictionary6.Add(key41, dictionary10);
Dictionary<string, Dictionary<string, string[]>> dictionary11 = dictionary5;
string key44 = "Silverlight";
Dictionary<string, string[]> dictionary12 = new Dictionary<string, string[]>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
Dictionary<string, string[]> dictionary13 = dictionary12;
string key45 = "WindowsPhone";
string[] strArray3 = new string[1];
int index3 = 0;
string str43 = "WindowsPhone71";
strArray3[index3] = str43;
dictionary13.Add(key45, strArray3);
Dictionary<string, string[]> dictionary14 = dictionary12;
string key46 = "WindowsPhone71";
string[] strArray4 = new string[1];
int index4 = 0;
string str44 = "WindowsPhone";
strArray4[index4] = str44;
dictionary14.Add(key46, strArray4);
Dictionary<string, string[]> dictionary15 = dictionary12;
dictionary11.Add(key44, dictionary15);
VersionUtility._compatibiltyMapping = dictionary5;
Dictionary<FrameworkName, FrameworkName> dictionary16 = new Dictionary<FrameworkName, FrameworkName>((IEqualityComparer<FrameworkName>) FrameworkNameEqualityComparer.Default);
FrameworkName key47 = new FrameworkName("WindowsPhone, Version=v0.0");
FrameworkName frameworkName1 = new FrameworkName("Silverlight, Version=v3.0, Profile=WindowsPhone");
dictionary16.Add(key47, frameworkName1);
FrameworkName key48 = new FrameworkName("WindowsPhone, Version=v7.0");
FrameworkName frameworkName2 = new FrameworkName("Silverlight, Version=v3.0, Profile=WindowsPhone");
dictionary16.Add(key48, frameworkName2);
FrameworkName key49 = new FrameworkName("WindowsPhone, Version=v7.1");
FrameworkName frameworkName3 = new FrameworkName("Silverlight, Version=v4.0, Profile=WindowsPhone71");
dictionary16.Add(key49, frameworkName3);
FrameworkName key50 = new FrameworkName("WindowsPhone, Version=v8.0");
FrameworkName frameworkName4 = new FrameworkName("Silverlight, Version=v8.0, Profile=WindowsPhone");
dictionary16.Add(key50, frameworkName4);
FrameworkName key51 = new FrameworkName("WindowsPhone, Version=v8.1");
FrameworkName frameworkName5 = new FrameworkName("Silverlight, Version=v8.1, Profile=WindowsPhone");
dictionary16.Add(key51, frameworkName5);
FrameworkName key52 = new FrameworkName("Windows, Version=v0.0");
FrameworkName frameworkName6 = new FrameworkName(".NETCore, Version=v4.5");
dictionary16.Add(key52, frameworkName6);
FrameworkName key53 = new FrameworkName("Windows, Version=v8.0");
FrameworkName frameworkName7 = new FrameworkName(".NETCore, Version=v4.5");
dictionary16.Add(key53, frameworkName7);
FrameworkName key54 = new FrameworkName("Windows, Version=v8.1");
FrameworkName frameworkName8 = new FrameworkName(".NETCore, Version=v4.5.1");
dictionary16.Add(key54, frameworkName8);
VersionUtility._frameworkNameAlias = dictionary16;
}
public static FrameworkName ParseFrameworkName(string frameworkName)
{
if (frameworkName == null)
throw new ArgumentNullException("frameworkName");
string str1 = (string) null;
string str2 = frameworkName;
char[] chArray = new char[1];
int index = 0;
int num = 45;
chArray[index] = (char) num;
string[] strArray = str2.Split(chArray);
if (strArray.Length > 2)
throw new ArgumentException(NuGetResources.InvalidFrameworkNameFormat, "frameworkName");
string input = strArray.Length > 0 ? strArray[0].Trim() : (string) null;
string str3 = strArray.Length > 1 ? strArray[1].Trim() : (string) null;
if (string.IsNullOrEmpty(input))
throw new ArgumentException(NuGetResources.MissingFrameworkName, "frameworkName");
Match match = Regex.Match(input, "\\d+");
string str4;
if (match.Success)
{
str4 = input.Substring(0, match.Index).Trim();
str1 = input.Substring(match.Index).Trim();
}
else
str4 = input.Trim();
if (!string.IsNullOrEmpty(str4) && !VersionUtility._knownIdentifiers.TryGetValue(str4, out str4))
return VersionUtility.UnsupportedFrameworkName;
string str5;
if (!string.IsNullOrEmpty(str3) && VersionUtility._knownProfiles.TryGetValue(str3, out str5))
str3 = str5;
Version result1 = (Version) null;
int result2;
if (int.TryParse(str1, out result2))
{
if (str1.Length > 4)
str1 = str1.Substring(0, 4);
str1 = string.Join<char>(".", (IEnumerable<char>) str1.PadRight(2, '0').ToCharArray());
}
if (!Version.TryParse(str1, out result1))
{
if (string.IsNullOrEmpty(str4) || !string.IsNullOrEmpty(str1))
return VersionUtility.UnsupportedFrameworkName;
result1 = VersionUtility._emptyVersion;
}
if (string.IsNullOrEmpty(str4))
str4 = ".NETFramework";
if (str4.Equals(".NETPortable", StringComparison.OrdinalIgnoreCase))
VersionUtility.ValidatePortableFrameworkProfilePart(str3);
return new FrameworkName(str4, result1, str3);
}
internal static void ValidatePortableFrameworkProfilePart(string profilePart)
{
if (string.IsNullOrEmpty(profilePart))
throw new ArgumentException(NuGetResources.PortableFrameworkProfileEmpty, "profilePart");
if (Enumerable.Contains<char>((IEnumerable<char>) profilePart, '-'))
throw new ArgumentException(NuGetResources.PortableFrameworkProfileHasDash, "profilePart");
if (Enumerable.Contains<char>((IEnumerable<char>) profilePart, ' '))
throw new ArgumentException(NuGetResources.PortableFrameworkProfileHasSpace, "profilePart");
string str = profilePart;
char[] chArray = new char[1];
int index = 0;
int num = 43;
chArray[index] = (char) num;
string[] strArray = str.Split(chArray);
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
if (Enumerable.Any<string>((IEnumerable<string>) strArray, VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate1 ?? (VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate1 = (Func<string, bool>) (p => string.IsNullOrEmpty(p)))))
throw new ArgumentException(NuGetResources.PortableFrameworkProfileComponentIsEmpty, "profilePart");
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
if (Enumerable.Any<string>((IEnumerable<string>) strArray, VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate3 ?? (VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate3 = (Func<string, bool>) (p => p.StartsWith("portable", StringComparison.OrdinalIgnoreCase)))) || Enumerable.Any<string>((IEnumerable<string>) strArray, VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate5 ?? (VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate5 = (Func<string, bool>) (p => p.StartsWith("NETPortable", StringComparison.OrdinalIgnoreCase)))) || Enumerable.Any<string>((IEnumerable<string>) strArray, VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate7 ?? (VersionUtility.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate7 = (Func<string, bool>) (p => p.StartsWith(".NETPortable", StringComparison.OrdinalIgnoreCase)))))
throw new ArgumentException(NuGetResources.PortableFrameworkProfileComponentIsPortable, "profilePart");
}
public static Version TrimVersion(Version version)
{
if (version == (Version) null)
throw new ArgumentNullException("version");
if (version.Build == 0 && version.Revision == 0)
version = new Version(version.Major, version.Minor);
else if (version.Revision == 0)
version = new Version(version.Major, version.Minor, version.Build);
return version;
}
public static IVersionSpec ParseVersionSpec(string value)
{
IVersionSpec result;
if (VersionUtility.TryParseVersionSpec(value, out result))
return result;
CultureInfo currentCulture = CultureInfo.CurrentCulture;
string invalidVersionString = NuGetResources.InvalidVersionString;
object[] objArray = new object[1];
int index = 0;
string str = value;
objArray[index] = (object) str;
throw new ArgumentException(string.Format((IFormatProvider) currentCulture, invalidVersionString, objArray));
}
public static bool TryParseVersionSpec(string value, out IVersionSpec result)
{
if (value == null)
throw new ArgumentNullException("value");
VersionSpec versionSpec1 = new VersionSpec();
value = value.Trim();
SemanticVersion version;
if (SemanticVersion.TryParse(value, out version))
{
// ISSUE: explicit reference operation
// ISSUE: variable of a reference type
IVersionSpec& local = @result;
VersionSpec versionSpec2 = new VersionSpec();
SemanticVersion semanticVersion = version;
versionSpec2.MinVersion = semanticVersion;
int num = 1;
versionSpec2.IsMinInclusive = num != 0;
// ISSUE: explicit reference operation
^local = (IVersionSpec) versionSpec2;
return true;
}
else
{
result = (IVersionSpec) null;
if (value.Length < 3)
return false;
switch (Enumerable.First<char>((IEnumerable<char>) value))
{
case '(':
versionSpec1.IsMinInclusive = false;
break;
case '[':
versionSpec1.IsMinInclusive = true;
break;
default:
return false;
}
switch (Enumerable.Last<char>((IEnumerable<char>) value))
{
case ')':
versionSpec1.IsMaxInclusive = false;
break;
case ']':
versionSpec1.IsMaxInclusive = true;
break;
default:
return false;
}
value = value.Substring(1, value.Length - 2);
string str = value;
char[] chArray = new char[1];
int index = 0;
int num = 44;
chArray[index] = (char) num;
string[] strArray = str.Split(chArray);
if (strArray.Length > 2 || Enumerable.All<string>((IEnumerable<string>) strArray, new Func<string, bool>(string.IsNullOrEmpty)))
return false;
string versionString1 = strArray[0];
string versionString2 = strArray.Length == 2 ? strArray[1] : strArray[0];
if (!string.IsNullOrWhiteSpace(versionString1))
{
if (!VersionUtility.TryParseVersion(versionString1, out version))
return false;
versionSpec1.MinVersion = version;
}
if (!string.IsNullOrWhiteSpace(versionString2))
{
if (!VersionUtility.TryParseVersion(versionString2, out version))
return false;
versionSpec1.MaxVersion = version;
}
result = (IVersionSpec) versionSpec1;
return true;
}
}
public static IVersionSpec GetSafeRange(SemanticVersion version)
{
VersionSpec versionSpec = new VersionSpec();
int num = 1;
versionSpec.IsMinInclusive = num != 0;
SemanticVersion semanticVersion1 = version;
versionSpec.MinVersion = semanticVersion1;
SemanticVersion semanticVersion2 = new SemanticVersion(new Version(version.Version.Major, version.Version.Minor + 1));
versionSpec.MaxVersion = semanticVersion2;
return (IVersionSpec) versionSpec;
}
public static string PrettyPrint(IVersionSpec versionSpec)
{
if (versionSpec.MinVersion != (SemanticVersion) null && versionSpec.IsMinInclusive && (versionSpec.MaxVersion == (SemanticVersion) null && !versionSpec.IsMaxInclusive))
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
string format = "({0} {1})";
object[] objArray = new object[2];
int index1 = 0;
string str = "≥";
objArray[index1] = (object) str;
int index2 = 1;
SemanticVersion minVersion = versionSpec.MinVersion;
objArray[index2] = (object) minVersion;
return string.Format((IFormatProvider) invariantCulture, format, objArray);
}
else if (versionSpec.MinVersion != (SemanticVersion) null && versionSpec.MaxVersion != (SemanticVersion) null && (versionSpec.MinVersion == versionSpec.MaxVersion && versionSpec.IsMinInclusive) && versionSpec.IsMaxInclusive)
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
string format = "(= {0})";
object[] objArray = new object[1];
int index = 0;
SemanticVersion minVersion = versionSpec.MinVersion;
objArray[index] = (object) minVersion;
return string.Format((IFormatProvider) invariantCulture, format, objArray);
}
else
{
StringBuilder stringBuilder1 = new StringBuilder();
if (versionSpec.MinVersion != (SemanticVersion) null)
{
if (versionSpec.IsMinInclusive)
{
StringBuilder stringBuilder2 = stringBuilder1;
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
string format = "({0} ";
object[] objArray = new object[1];
int index = 0;
string str = "≥";
objArray[index] = (object) str;
stringBuilder2.AppendFormat((IFormatProvider) invariantCulture, format, objArray);
}
else
stringBuilder1.Append("(> ");
stringBuilder1.Append((object) versionSpec.MinVersion);
}
if (versionSpec.MaxVersion != (SemanticVersion) null)
{
if (stringBuilder1.Length == 0)
stringBuilder1.Append("(");
else
stringBuilder1.Append(" && ");
if (versionSpec.IsMaxInclusive)
{
StringBuilder stringBuilder2 = stringBuilder1;
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
string format = "{0} ";
object[] objArray = new object[1];
int index = 0;
string str = "≤";
objArray[index] = (object) str;
stringBuilder2.AppendFormat((IFormatProvider) invariantCulture, format, objArray);
}
else
stringBuilder1.Append("< ");
stringBuilder1.Append((object) versionSpec.MaxVersion);
}
if (stringBuilder1.Length > 0)
stringBuilder1.Append(")");
return ((object) stringBuilder1).ToString();
}
}
public static string GetFrameworkString(FrameworkName frameworkName)
{
string str = frameworkName.Identifier + (object) frameworkName.Version;
if (string.IsNullOrEmpty(frameworkName.Profile))
return str;
else
return str + "-" + frameworkName.Profile;
}
public static string GetShortFrameworkName(FrameworkName frameworkName)
{
if (frameworkName == (FrameworkName) null)
throw new ArgumentNullException("frameworkName");
foreach (KeyValuePair<FrameworkName, FrameworkName> keyValuePair in VersionUtility._frameworkNameAlias)
{
if (FrameworkNameEqualityComparer.Default.Equals(keyValuePair.Value, frameworkName))
{
frameworkName = keyValuePair.Key;
break;
}
}
string str1;
if (!VersionUtility._identifierToFrameworkFolder.TryGetValue(frameworkName.Identifier, out str1))
str1 = frameworkName.Identifier;
string str2;
if (str1.Equals("portable", StringComparison.OrdinalIgnoreCase))
{
NetPortableProfile netPortableProfile = NetPortableProfile.Parse(frameworkName.Profile, false);
str2 = netPortableProfile == null ? frameworkName.Profile : netPortableProfile.CustomProfileString;
}
else
{
if (frameworkName.Version > new Version())
str1 = str1 + ((object) frameworkName.Version).ToString().Replace(".", string.Empty);
if (string.IsNullOrEmpty(frameworkName.Profile))
return str1;
if (!VersionUtility._identifierToProfileFolder.TryGetValue(frameworkName.Profile, out str2))
str2 = frameworkName.Profile;
}
return str1 + "-" + str2;
}
public static string GetTargetFrameworkLogString(FrameworkName targetFramework)
{
if (!(targetFramework == (FrameworkName) null) && !(targetFramework == VersionUtility.EmptyFramework))
return string.Empty;
else
return NuGetResources.Debug_TargetFrameworkInfo_NotFrameworkSpecific;
}
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#")]
public static FrameworkName ParseFrameworkNameFromFilePath(string filePath, out string effectivePath)
{
string[] strArray1 = new string[4];
int index1 = 0;
string str1 = Constants.ContentDirectory;
strArray1[index1] = str1;
int index2 = 1;
string str2 = Constants.LibDirectory;
strArray1[index2] = str2;
int index3 = 2;
string str3 = Constants.ToolsDirectory;
strArray1[index3] = str3;
int index4 = 3;
string str4 = Constants.BuildDirectory;
strArray1[index4] = str4;
string[] strArray2 = strArray1;
for (int index5 = 0; index5 < strArray2.Length; ++index5)
{
string str5 = strArray2[index5] + (object) Path.DirectorySeparatorChar;
if (filePath.Length > str5.Length && filePath.StartsWith(str5, StringComparison.OrdinalIgnoreCase))
{
string path = filePath.Substring(str5.Length);
try
{
return VersionUtility.ParseFrameworkFolderName(path, strArray2[index5] == Constants.LibDirectory, out effectivePath);
}
catch (ArgumentException ex)
{
effectivePath = path;
return (FrameworkName) null;
}
}
}
effectivePath = filePath;
return (FrameworkName) null;
}
public static FrameworkName ParseFrameworkFolderName(string path)
{
string effectivePath;
return VersionUtility.ParseFrameworkFolderName(path, true, out effectivePath);
}
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#")]
public static FrameworkName ParseFrameworkFolderName(string path, bool strictParsing, out string effectivePath)
{
string directoryName = Path.GetDirectoryName(path);
char[] chArray = new char[1];
int index = 0;
int num = (int) Path.DirectorySeparatorChar;
chArray[index] = (char) num;
string frameworkName1 = Enumerable.First<string>((IEnumerable<string>) directoryName.Split(chArray));
effectivePath = path;
if (string.IsNullOrEmpty(frameworkName1))
return (FrameworkName) null;
FrameworkName frameworkName2 = VersionUtility.ParseFrameworkName(frameworkName1);
if (!strictParsing && !(frameworkName2 != VersionUtility.UnsupportedFrameworkName))
return (FrameworkName) null;
effectivePath = path.Substring(frameworkName1.Length + 1);
return frameworkName2;
}
public static bool TryGetCompatibleItems<T>(FrameworkName projectFramework, IEnumerable<T> items, out IEnumerable<T> compatibleItems) where T : IFrameworkTargetable
{
if (!Enumerable.Any<T>(items))
{
compatibleItems = Enumerable.Empty<T>();
return true;
}
else
{
FrameworkName internalProjectFramework = projectFramework ?? VersionUtility.EmptyFramework;
List<IGrouping<FrameworkName, T>> list = Enumerable.ToList<IGrouping<FrameworkName, T>>(Enumerable.GroupBy(Enumerable.SelectMany(Enumerable.Select(items, item => new
{
item = item,
frameworks = item.SupportedFrameworks == null || !Enumerable.Any<FrameworkName>(item.SupportedFrameworks) ? (IEnumerable<FrameworkName>) new FrameworkName[1] : item.SupportedFrameworks
}), param0 => param0.frameworks, (param0, framework) => new
{
Item = param0.item,
TargetFramework = framework
}), g => g.TargetFramework, g => g.Item));
compatibleItems = (IEnumerable<T>) Enumerable.FirstOrDefault<IGrouping<FrameworkName, T>>((IEnumerable<IGrouping<FrameworkName, T>>) Enumerable.OrderByDescending<IGrouping<FrameworkName, T>, long>(Enumerable.Where<IGrouping<FrameworkName, T>>((IEnumerable<IGrouping<FrameworkName, T>>) list, (Func<IGrouping<FrameworkName, T>, bool>) (g =>
{
if (g.Key != (FrameworkName) null)
return VersionUtility.IsCompatible(internalProjectFramework, g.Key);
else
return false;
})), (Func<IGrouping<FrameworkName, T>, long>) (g => VersionUtility.GetProfileCompatibility(internalProjectFramework, g.Key))));
bool flag = compatibleItems != null && Enumerable.Any<T>(compatibleItems);
if (!flag)
{
compatibleItems = Enumerable.SelectMany<IGrouping<FrameworkName, T>, T>(Enumerable.Where<IGrouping<FrameworkName, T>>((IEnumerable<IGrouping<FrameworkName, T>>) list, (Func<IGrouping<FrameworkName, T>, bool>) (g => g.Key == (FrameworkName) null)), (Func<IGrouping<FrameworkName, T>, IEnumerable<T>>) (g => (IEnumerable<T>) g));
flag = compatibleItems != null && Enumerable.Any<T>(compatibleItems);
}
if (!flag)
compatibleItems = (IEnumerable<T>) null;
return flag;
}
}
internal static Version NormalizeVersion(Version version)
{
return new Version(version.Major, version.Minor, Math.Max(version.Build, 0), Math.Max(version.Revision, 0));
}
internal static FrameworkName NormalizeFrameworkName(FrameworkName framework)
{
FrameworkName frameworkName;
if (VersionUtility._frameworkNameAlias.TryGetValue(framework, out frameworkName))
return frameworkName;
else
return framework;
}
internal static IEnumerable<SemanticVersion> GetPossibleVersions(SemanticVersion semVer)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
VersionUtility.\u003CGetPossibleVersions\u003Ed__19 possibleVersionsD19 = new VersionUtility.\u003CGetPossibleVersions\u003Ed__19(-2);
SemanticVersion semanticVersion = semVer;
// ISSUE: reference to a compiler-generated field
possibleVersionsD19.\u003C\u003E3__semVer = semanticVersion;
return (IEnumerable<SemanticVersion>) possibleVersionsD19;
}
public static bool IsCompatible(FrameworkName projectFrameworkName, IEnumerable<FrameworkName> packageSupportedFrameworks)
{
if (Enumerable.Any<FrameworkName>(packageSupportedFrameworks))
return Enumerable.Any<FrameworkName>(packageSupportedFrameworks, (Func<FrameworkName, bool>) (packageSupportedFramework => VersionUtility.IsCompatible(projectFrameworkName, packageSupportedFramework)));
else
return true;
}
internal static bool IsCompatible(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName)
{
if (projectFrameworkName == (FrameworkName) null)
return true;
if (VersionUtility.IsPortableFramework(packageTargetFrameworkName))
return VersionUtility.IsPortableLibraryCompatible(projectFrameworkName, packageTargetFrameworkName);
packageTargetFrameworkName = VersionUtility.NormalizeFrameworkName(packageTargetFrameworkName);
projectFrameworkName = VersionUtility.NormalizeFrameworkName(projectFrameworkName);
if (!projectFrameworkName.Identifier.Equals(packageTargetFrameworkName.Identifier, StringComparison.OrdinalIgnoreCase) || VersionUtility.NormalizeVersion(projectFrameworkName.Version) < VersionUtility.NormalizeVersion(packageTargetFrameworkName.Version))
return false;
if (string.Equals(projectFrameworkName.Profile, packageTargetFrameworkName.Profile, StringComparison.OrdinalIgnoreCase))
return true;
Dictionary<string, string[]> dictionary;
string[] strArray;
if (VersionUtility._compatibiltyMapping.TryGetValue(projectFrameworkName.Identifier, out dictionary) && dictionary.TryGetValue(packageTargetFrameworkName.Profile, out strArray))
return Enumerable.Contains<string>((IEnumerable<string>) strArray, projectFrameworkName.Profile, (IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
else
return false;
}
private static bool IsPortableLibraryCompatible(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName)
{
if (string.IsNullOrEmpty(packageTargetFrameworkName.Profile))
return false;
NetPortableProfile netPortableProfile = NetPortableProfile.Parse(packageTargetFrameworkName.Profile, false);
if (netPortableProfile == null)
return false;
if (!VersionUtility.IsPortableFramework(projectFrameworkName))
return netPortableProfile.IsCompatibleWith(projectFrameworkName);
if (string.Equals(projectFrameworkName.Profile, packageTargetFrameworkName.Profile, StringComparison.OrdinalIgnoreCase))
return true;
NetPortableProfile projectFrameworkProfile = NetPortableProfile.Parse(projectFrameworkName.Profile, false);
if (projectFrameworkProfile == null)
return false;
else
return netPortableProfile.IsCompatibleWith(projectFrameworkProfile);
}
private static long GetProfileCompatibility(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName)
{
projectFrameworkName = VersionUtility.NormalizeFrameworkName(projectFrameworkName);
packageTargetFrameworkName = VersionUtility.NormalizeFrameworkName(packageTargetFrameworkName);
if (VersionUtility.IsPortableFramework(packageTargetFrameworkName))
{
if (VersionUtility.IsPortableFramework(projectFrameworkName))
return (long) VersionUtility.GetCompatibilityBetweenPortableLibraryAndPortableLibrary(projectFrameworkName, packageTargetFrameworkName);
else
return VersionUtility.GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(projectFrameworkName, packageTargetFrameworkName) / 2L;
}
else
{
long num = 0L + VersionUtility.CalculateVersionDistance(projectFrameworkName.Version, VersionUtility.GetEffectiveFrameworkVersion(projectFrameworkName, packageTargetFrameworkName));
if (packageTargetFrameworkName.Profile.Equals(projectFrameworkName.Profile, StringComparison.OrdinalIgnoreCase))
++num;
if (packageTargetFrameworkName.Identifier.Equals(projectFrameworkName.Identifier, StringComparison.OrdinalIgnoreCase))
num += 42949672960L;
return num;
}
}
private static long CalculateVersionDistance(Version projectVersion, Version targetFrameworkVersion)
{
return 137438953472L - ((long) (projectVersion.Major - targetFrameworkVersion.Major) * (long) byte.MaxValue * (long) byte.MaxValue * (long) byte.MaxValue + (long) (projectVersion.Minor - targetFrameworkVersion.Minor) * (long) byte.MaxValue * (long) byte.MaxValue + (long) (projectVersion.Build - targetFrameworkVersion.Build) * (long) byte.MaxValue + (long) (projectVersion.Revision - targetFrameworkVersion.Revision));
}
private static Version GetEffectiveFrameworkVersion(FrameworkName projectFramework, FrameworkName targetFrameworkVersion)
{
if (VersionUtility.IsPortableFramework(targetFrameworkVersion))
{
NetPortableProfile netPortableProfile = NetPortableProfile.Parse(targetFrameworkVersion.Profile, false);
if (netPortableProfile != null)
{
FrameworkName frameworkName = Enumerable.FirstOrDefault<FrameworkName>((IEnumerable<FrameworkName>) netPortableProfile.SupportedFrameworks, (Func<FrameworkName, bool>) (f => VersionUtility.IsCompatible(projectFramework, f)));
if (frameworkName != (FrameworkName) null)
return frameworkName.Version;
}
}
return targetFrameworkVersion.Version;
}
internal static int GetCompatibilityBetweenPortableLibraryAndPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName)
{
NetPortableProfile netPortableProfile1 = NetPortableProfile.Parse(projectFrameworkName.Profile, false);
NetPortableProfile netPortableProfile2 = NetPortableProfile.Parse(packageTargetFrameworkName.Profile, true);
int num1 = 0;
int num2 = 0;
foreach (FrameworkName frameworkName1 in (IEnumerable<FrameworkName>) netPortableProfile2.SupportedFrameworks)
{
FrameworkName supportedPackageTargetFramework = frameworkName1;
FrameworkName frameworkName2 = Enumerable.FirstOrDefault<FrameworkName>((IEnumerable<FrameworkName>) netPortableProfile1.SupportedFrameworks, (Func<FrameworkName, bool>) (f => VersionUtility.IsCompatible(f, supportedPackageTargetFramework)));
if (frameworkName2 != (FrameworkName) null && frameworkName2.Version > supportedPackageTargetFramework.Version)
++num1;
}
foreach (FrameworkName frameworkName1 in (IEnumerable<FrameworkName>) netPortableProfile1.OptionalFrameworks)
{
FrameworkName optionalProjectFramework = frameworkName1;
FrameworkName frameworkName2 = Enumerable.FirstOrDefault<FrameworkName>((IEnumerable<FrameworkName>) netPortableProfile2.SupportedFrameworks, (Func<FrameworkName, bool>) (f => VersionUtility.IsCompatible(f, optionalProjectFramework)));
if (frameworkName2 == (FrameworkName) null || frameworkName2.Version > optionalProjectFramework.Version)
++num2;
else if (frameworkName2 != (FrameworkName) null && frameworkName2.Version < optionalProjectFramework.Version)
++num1;
}
return -(((1 + netPortableProfile1.SupportedFrameworks.Count + netPortableProfile1.OptionalFrameworks.Count) * num2 + num1) * 50 + netPortableProfile2.SupportedFrameworks.Count);
}
internal static long GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packagePortableFramework)
{
NetPortableProfile packageFramework = NetPortableProfile.Parse(packagePortableFramework.Profile, true);
if (packageFramework == null)
return long.MinValue;
FrameworkName packageTargetFrameworkName = Enumerable.FirstOrDefault<FrameworkName>((IEnumerable<FrameworkName>) packageFramework.SupportedFrameworks, (Func<FrameworkName, bool>) (f => VersionUtility.IsCompatible(projectFrameworkName, f)));
if (packageTargetFrameworkName != (FrameworkName) null)
return VersionUtility.GetProfileCompatibility(projectFrameworkName, packageTargetFrameworkName) - (long) (packageFramework.SupportedFrameworks.Count * 2);
if (NetPortableProfileTable.HasCompatibleProfileWith(packageFramework, projectFrameworkName))
return (long) -(packageFramework.SupportedFrameworks.Count * 2);
else
return long.MinValue;
}
private static bool TryParseVersion(string versionString, out SemanticVersion version)
{
version = (SemanticVersion) null;
int result;
if (!SemanticVersion.TryParse(versionString, out version) && int.TryParse(versionString, out result) && result > 0)
version = new SemanticVersion(new Version(result, 0));
return version != (SemanticVersion) null;
}
internal static bool IsPortableFramework(this FrameworkName framework)
{
if (framework != (FrameworkName) null)
return ".NETPortable".Equals(framework.Identifier, StringComparison.OrdinalIgnoreCase);
else
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment