From 051aa600e4a721f7eacd02d6e50b6605d3ada24d Mon Sep 17 00:00:00 2001
From: Siegfried Pammer <siegfriedpammer@gmail.com>
Date: Sat, 10 Sep 2022 13:22:54 +0200
Subject: [PATCH] Move LanguageVersion to ILSpyX.

---
 ICSharpCode.ILSpyX/LanguageVersion.cs | 40 +++++++++++++++++++++++++++
 ILSpy/DecompilationOptions.cs         |  1 +
 ILSpy/Languages/CSharpLanguage.cs     |  2 ++
 ILSpy/Languages/Language.cs           | 31 ++++-----------------
 ILSpy/ViewModels/TabPageModel.cs      |  1 +
 5 files changed, 50 insertions(+), 25 deletions(-)
 create mode 100644 ICSharpCode.ILSpyX/LanguageVersion.cs

diff --git a/ICSharpCode.ILSpyX/LanguageVersion.cs b/ICSharpCode.ILSpyX/LanguageVersion.cs
new file mode 100644
index 000000000..0300f5db2
--- /dev/null
+++ b/ICSharpCode.ILSpyX/LanguageVersion.cs
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+namespace ICSharpCode.ILSpyX
+{
+	/// <summary>
+	/// Version-DisplayName pair used in UI scenarios, for example ILSpy's language version dropdown.
+	/// </summary>
+	public class LanguageVersion
+	{
+		public string Version { get; }
+		public string DisplayName { get; }
+
+		public LanguageVersion(string version, string? name = null)
+		{
+			Version = version ?? "";
+			DisplayName = name ?? Version.ToString();
+		}
+
+		public override string ToString()
+		{
+			return $"[LanguageVersion DisplayName={DisplayName}, Version={Version}]";
+		}
+	}
+}
diff --git a/ILSpy/DecompilationOptions.cs b/ILSpy/DecompilationOptions.cs
index 1218b20f6..0b95dd0ea 100644
--- a/ILSpy/DecompilationOptions.cs
+++ b/ILSpy/DecompilationOptions.cs
@@ -20,6 +20,7 @@ using System;
 using System.Threading;
 
 using ICSharpCode.ILSpy.Options;
+using ICSharpCode.ILSpyX;
 
 namespace ICSharpCode.ILSpy
 {
diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs
index 2e6f3343f..ae1e4e0e4 100644
--- a/ILSpy/Languages/CSharpLanguage.cs
+++ b/ILSpy/Languages/CSharpLanguage.cs
@@ -47,6 +47,8 @@ using ICSharpCode.ILSpy.TextView;
 using ICSharpCode.ILSpy.TreeNodes;
 using ICSharpCode.ILSpyX;
 
+using LanguageVersion = ICSharpCode.ILSpyX.LanguageVersion;
+
 namespace ICSharpCode.ILSpy
 {
 	/// <summary>
diff --git a/ILSpy/Languages/Language.cs b/ILSpy/Languages/Language.cs
index ecf626dbd..b47acbaad 100644
--- a/ILSpy/Languages/Language.cs
+++ b/ILSpy/Languages/Language.cs
@@ -32,27 +32,8 @@ using ICSharpCode.Decompiler.Util;
 using ICSharpCode.ILSpyX;
 using ICSharpCode.ILSpyX.Abstractions;
 
-using SRM = System.Reflection.Metadata;
-
 namespace ICSharpCode.ILSpy
 {
-	public class LanguageVersion
-	{
-		public string Version { get; }
-		public string DisplayName { get; }
-
-		public LanguageVersion(string version, string name = null)
-		{
-			this.Version = version ?? "";
-			this.DisplayName = name ?? version.ToString();
-		}
-
-		public override string ToString()
-		{
-			return $"[LanguageVersion DisplayName={DisplayName}, Version={Version}]";
-		}
-	}
-
 	/// <summary>
 	/// Base class for language-specific decompiler implementations.
 	/// </summary>
@@ -84,9 +65,9 @@ namespace ICSharpCode.ILSpy
 		/// <summary>
 		/// Gets the syntax highlighting used for this language.
 		/// </summary>
-		public virtual ICSharpCode.AvalonEdit.Highlighting.IHighlightingDefinition SyntaxHighlighting {
+		public virtual IHighlightingDefinition SyntaxHighlighting {
 			get {
-				return ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(this.FileExtension);
+				return HighlightingManager.Instance.GetDefinitionByExtension(FileExtension);
 			}
 		}
 
@@ -541,13 +522,13 @@ namespace ICSharpCode.ILSpy
 			}
 		}
 
-		public virtual CodeMappingInfo GetCodeMappingInfo(PEFile module, SRM.EntityHandle member)
+		public virtual CodeMappingInfo GetCodeMappingInfo(PEFile module, EntityHandle member)
 		{
-			var declaringType = (SRM.TypeDefinitionHandle)member.GetDeclaringType(module.Metadata);
+			var declaringType = (TypeDefinitionHandle)member.GetDeclaringType(module.Metadata);
 
-			if (declaringType.IsNil && member.Kind == SRM.HandleKind.TypeDefinition)
+			if (declaringType.IsNil && member.Kind == HandleKind.TypeDefinition)
 			{
-				declaringType = (SRM.TypeDefinitionHandle)member;
+				declaringType = (TypeDefinitionHandle)member;
 			}
 
 			return new CodeMappingInfo(module, declaringType);
diff --git a/ILSpy/ViewModels/TabPageModel.cs b/ILSpy/ViewModels/TabPageModel.cs
index 91903f678..836560c2c 100644
--- a/ILSpy/ViewModels/TabPageModel.cs
+++ b/ILSpy/ViewModels/TabPageModel.cs
@@ -22,6 +22,7 @@ using System.Linq;
 using System.Threading.Tasks;
 
 using ICSharpCode.ILSpy.TextView;
+using ICSharpCode.ILSpyX;
 
 namespace ICSharpCode.ILSpy.ViewModels
 {