码迷,mamicode.com
首页 > Windows程序 > 详细

C#控制台 assembly与gettypes获取一个dll中的类的名字

时间:2016-10-21 00:37:10      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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 ClassLibrary1
 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                 Console.WriteLine(item.Name);
21             }
22 
23             Console.ReadKey();
24         }
25     }
26 }

 

 

 

3 show

技术分享

 

C#控制台 assembly与gettypes获取一个dll中的类的名字

标签:

原文地址:http://www.cnblogs.com/jinlingzi/p/5982866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!