摘要: 在项目中为了方便,写了一个简单的扩展方法:1 public static T ToEntity(this DataRow dr){};//将一行数据转换为对应的实体 之前还运行良好,但是自从把数据库中一个字段改为可空类型后,就出现问题了。 比如对于int?类型,也就是Nullable类型的属性,如果数据为DBNull还好说,直接将null赋值给int?也是安全的,但是如果有值,比如string类型"12"的话,在强制类型转换的时候就出现如下错误:从“System.String”到“System.Nullable`1[[System.Int32, mscorlib, Vers 阅读全文
posted @ 2014-01-20 21:43 CrisiDoff 阅读(657) 评论(0) 推荐(0) 编辑
摘要: 1 EventInfo[] einf = this.控件.GetType().GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);2 if (einf != null && einf.Length > 0)3 {4 foreach (var item in einf)5 {6 FieldInfo finfo = item.Decl... 阅读全文
posted @ 2013-08-16 00:35 CrisiDoff 阅读(196) 评论(0) 推荐(0) 编辑