/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/standard/assembly/snippets/identify/csharp/ExampleAssemblyName.cs
38 строк
968 B
MSDN.WhiteKnight
Improve How to determine if a file is an assembly (#25329)
02 авг 2021, 22:54
Не верифицирован
02 авг 2021, 22:54
5c10176
Код
Авторство
О чём код?
//<SnippetAssemblyName> using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; static class ExampleAssemblyName { public static void CheckAssembly() { try { string path = Path.Combine( RuntimeEnvironment.GetRuntimeDirectory(), "System.Net.dll"); AssemblyName testAssembly = AssemblyName.GetAssemblyName(path); Console.WriteLine("Yes, the file is an assembly."); } catch (FileNotFoundException) { Console.WriteLine("The file cannot be found."); } catch (BadImageFormatException) { Console.WriteLine("The file is not an assembly."); } catch (FileLoadException) { Console.WriteLine("The assembly has already been loaded."); } } /* Output: Yes, the file is an assembly. */ } //</SnippetAssemblyName>