首页 > 代码库 > C#控制台 assembly与fullname获取一个dll中所有的命名空间

C#控制台 assembly与fullname获取一个dll中所有的命名空间

1 dll中有两个类

class1

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ClassLibrary1
 8 {
 9     public class Student
10     {
11         private int _ageStudent;
12         private string _nameStudent;
13         public int AgeStudent { get; set; }
14         public int NameStudent { get; set; }
15         public void HelloWorldStudent() { Console.WriteLine("hello world,i am a Student"); }
16 
17     }
18 }

 

class2

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ClassLibraryNew
 8 {
 9     public class Teacher
10     {
11         private int _ageTeacher;
12         private string _nameTeacher;
13         public int AgeTeacher { get; set; }
14         public int NameTeacher { get; set; }
15         public void HelloWorldTeacher(){Console.WriteLine("hello world,i am a teacher");}
16     }
17 }

 

2 code

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Reflection;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace ConsoleApplication13
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             string path = @"D:\用户目录\我的文档\visual studio 2015\Projects\ConsoleApplication13\ClassLibrary1\bin\Debug\ClassLibrary1.dll";
15             Assembly dllFile = Assembly.LoadFile(path);
16             Type[] classType = dllFile.GetTypes();
17 
18             foreach (var item in classType)
19             {
20                 //item现在是类
21                 Console.WriteLine(item.FullName);
22             }
23 
24             Console.ReadKey();
25         }
26     }
27 }

 

3 show

技术分享

 

C#控制台 assembly与fullname获取一个dll中所有的命名空间