c# 反射
--随手记下
//方法 GetField() 1.获取所有公开的访问字段
//GetField(string fieldName) 2.获取特定名称的字段
//GetProperties() 3.获取所有公开的属性
//GetProperty(string propertieName) 4.获取特定名称的属性
//GetMethods() 5.获取所有公开的方法
//通过反射更新功能
// (1)using System.Reflection; //泛着dll的类库
// (2)Environment.CurrentDirectory 可以动态的获取文件路径
// (3) Assembly ass=Assembly.LoadFile(dll的路径);
// (4)ass.GetTypes(); //获取所有的声明类型 //ass.GetType(string typeName)
// (5) ass.CreateInstance(FullName(完全限定名));
// 最后就进行操作方法或者类
var ss = Assembly.Load(Environment.CurrentDirectory + "/ss.dll");
ss.GetTypes().Where(w => !w.IsAbstract && w.IsClass);
[Test] public void MyTest() { //Excel文件的路径 var mapper = new Mapper("Students.xlsx"); // map的方式 mapper.Map<Student>(0, "Id", tryTake: (o, d) => { if (o.HeaderValue == null && o.CurrentValue == null) { return false; } else { ((Student)d).Id = 99999; return false; } }); var objs = mapper.Take<Student>(0).ToList(); } public class Student { public int Id { get; set; } public string Name { get; set; } public string Sex { get; set; } public DateTime BirthDay { get; set; } }
[Test] public void MyTest() { //Excel文件的路径 var mapper = new Mapper("Students.xlsx");
// map的方式 mapper.Map<Student>(0, "Id", tryTake: (o, d) => { if (o.HeaderValue == null && o.CurrentValue == null) { return false; } else { ((Student)d).Id = 99999; return false; } }); var objs = mapper.Take<Student>(0).ToList(); }
public class Student { public int Id { get; set; } public string Name { get; set; } public string Sex { get; set; } public DateTime BirthDay { get; set; } }