From 7bff426ac3316125acfdb75b9a3d7127933578b7 Mon Sep 17 00:00:00 2001 From: Grega Mohorko Date: Fri, 20 Oct 2017 20:28:26 +0200 Subject: [PATCH] Update ReflectionUtility.cs --- .../GM.Utility/ReflectionUtility.cs | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/GM.Utility/GM.Utility/ReflectionUtility.cs b/src/GM.Utility/GM.Utility/ReflectionUtility.cs index 1f54f4d..97f8c0a 100644 --- a/src/GM.Utility/GM.Utility/ReflectionUtility.cs +++ b/src/GM.Utility/GM.Utility/ReflectionUtility.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -134,12 +135,40 @@ public static AssemblyInformation GetAssemblyInformation(Assembly assembly) } /// - /// Gets the local (operating-system wise) path of the assembly that defines the specified type. + /// Gets the local (operating-system wise) directory path of the assembly that defines the specified type. /// - /// The type that is defined in the assembly of which to get the local path. - public static string GetAssemblyLocalPath(Type type) + /// The type that is defined in the assembly of which to get the local directory path. + public static string GetAssemblyDirectoryLocalPath(Type type) { - string codebase = type.Assembly.CodeBase; + return GetAssemblyDirectoryLocalPath(type.Assembly); + } + + /// + /// Gets the local (operating-system wise) directory path of the specified assembly. + /// + /// The assembly. + public static string GetAssemblyDirectoryLocalPath(Assembly assembly) + { + string filePath = GetAssemblyFileLocalPath(assembly); + return Path.GetDirectoryName(filePath); + } + + /// + /// Gets the local (operating-system wise) file (.dll) path of the assembly that defines the specified type. + /// + /// The type that is defined in the assembly of which to get the local file path. + public static string GetAssemblyFileLocalPath(Type type) + { + return GetAssemblyFileLocalPath(type.Assembly); + } + + /// + /// Gets the local (operating-system wise) file (.dll) path of the specified assembly. + /// + /// The assembly. + public static string GetAssemblyFileLocalPath(Assembly assembly) + { + string codebase = assembly.CodeBase; var uri = new Uri(codebase, UriKind.Absolute); return uri.LocalPath; }