/// <summary> /// Serialize the object using the DataContractSerializer to the file specified. If the file /// exists it will be overwritten and it requires an exclusive write lock on the file. /// </summary> /// <param name="path">The filename to write the serialization string to</param> /// <param name="encoding">The encoding to use when serializing.</param> /// <param name="entity">The entity to serialize.</param> /// <returns></returns> public static void ToXmlInFile <T>(string path, Encoding encoding, T entity) { var serializer = new DataContractSerializer(typeof(T)); var filename = SmartLocation.GetLocation(path); using (var writer = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) { serializer.WriteObject(writer, entity); } }
/// <summary> /// Deserialize the object using the DataContractSerializer from the file specified. If the file /// does not exist then an exception will be thrown /// </summary> /// <param name="path">The fully qualified path to the file</param> /// <param name="encoding">The encoding to use when deserializing.</param> /// <returns></returns> public static T FromXmlInFile <T>(string path, Encoding encoding) { var serializer = new DataContractSerializer(typeof(T)); var filename = SmartLocation.GetLocation(path); using (var reader = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { return((T)serializer.ReadObject(reader)); } }
static TypeDiscovery() { _binFolder = SmartLocation.GetBinFolder(); _config = Container.Resolve <TypeDiscoveryConfig>(); _filesToExclude = new List <string>(); var exclude = new List <string>(); if (_config.Exclude == null) { return; } _config.Exclude.ForEach(e => exclude.AddRange(Directory.GetFiles(_binFolder, e))); _filesToExclude = exclude.Distinct().ToList(); }
/// <summary> /// Static inline version of the <see cref="Location"/> property /// </summary> /// <param name="rawLocation">The "raw" location</param> /// <returns>The resolved location consistent for the application context/environment</returns> public static string GetLocation(string rawLocation) { var sl = new SmartLocation(rawLocation); return(sl.Location); }
/// <summary> /// Static inline version of the <see cref="Location"/> property /// </summary> /// <param name="rawLocation">The "raw" location</param> /// <returns>The resolved location consistent for the application context/environment</returns> public static string GetLocation(string rawLocation) { var sl = new SmartLocation(rawLocation); return sl.Location; }