Home >Backend Development >C#.Net Tutorial >C# Assembly class accesses assembly information

C# Assembly class accesses assembly information

黄舟
黄舟Original
2016-12-15 14:23:121729browse

In C#, assembly information can be accessed through the Assembly class.
1. Allows access to meta elements of a given assembly, including methods that can load and execute the assembly;
2. Load an assembly: Use the static method Assembly.Load(program Assembly name) or Assembly.LoadFrom (assembly full path name);
3. Attributes:
FullName: Assembly display name;
3. Methods:
GetTypes(): Get the types defined in the assembly.
TestAssembly.cs:
view plaincopy to clipboardprint?
using System; using System.Reflection;
namespace Magci.Test.Reflection
{ public class TestAssembly
{ public static void Main()
{ //Load the assembly into the runtime In the process
Assembly ass = Assembly.Load("TestCustomAttributes");
Assembly ass1 = Assembly.LoadFrom(@"E:CODEdotNetC#9-ReflectionTestCustomAttributes.dll");
//Get the assembly display name
Console.WriteLine( ass1.FullName);
//Get the types defined in the assembly
Type[] types = ass.GetTypes();
foreach (Type t in types)
{ Console.WriteLine(t.FullName);
} } } }

The above is the content of the C# Assembly class to access assembly information. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn