随笔分类 -  C#

获取EnterpriseLibrary企业库配置文件中ConnectionStrings(原创)
摘要:在使用企业类库时想取出单独企业配置文件中的连接字符串遍历,并放到自己的数据库处理类中,在查找了很久的资料后都没有找到,于是自己探索着写了一个,共享给大家以做参考:ConfigurationSourceSection sec = (ConfigurationSourceSection)ConfigurationManager.GetSection("enterpriseLibrary.ConfigurationSource"); PolymorphicConfigurationElementCollection po = (PolymorphicConfigurationE. 阅读全文
posted @ 2013-07-31 15:05 Johnliu 阅读(355) 评论(1) 推荐(0)
序列化反序列化只读属性解决方案(原创)
摘要:/// /// 通过反射实现具有只读属性的类的序列化 /// 类必私有变量必须是"_"+属性名称 /// public abstract class ReadOnlySerializable : IXmlSerializable { #region X... 阅读全文
posted @ 2013-07-12 10:44 Johnliu 阅读(801) 评论(0) 推荐(0)
将未知类型的数组执行遍历操作(原创)
摘要:通常我们传入一个IEnumerable的参数,而这个参数,这个参数可能是IEnumerable也有可能是IEnumerable,当时IEnumerable时IEnumerable values = (IEnumerable)ObjectValue; foreach (var item in values){} 当IEnumerable却会报无法转换的错误,所以通用的正确做法是:((IEnumerable)ObjectValue).Cast() 阅读全文
posted @ 2013-07-02 12:18 Johnliu 阅读(347) 评论(0) 推荐(0)
Dictionary序列化/反序列化
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml.Schema;using System.Xml.Serialization;using System.Xml;namespace JohnCore.MyClass{ [XmlRoot("dictionary")] public class SerializableDictionary<TKey, TValue>: Dictionary<TKey, TValue& 阅读全文
posted @ 2013-06-11 11:17 Johnliu 阅读(266) 评论(0) 推荐(0)