| public static BlogConfigurationSettings Instance(HttpContext context) { //在实际的应用中,别忘了加上缓存 string filepath = context.Server.MapPath("~/blog.config"); settings = (BlogConfigurationSettings)LoadSerializedObject(typeof(BookConfigurationSettings),filepath); return settings; } public static object LoadSerializedObject(Type type, string filename) { FileStream fs = null; try { // open the stream fs = new FileStream(filename, FileMode.Open,FileAccess.Read); XmlSerializer serializer = new XmlSerializer(type); return serializer.Deserialize(fs); } catch(Exception e) { throw e; } finally { if(fs != null) fs.Close(); } }
|