Ejemplo n.º 1
0
        /// <summary>
        /// Load an instance of type <typeparamref name="T"/> from <paramref name="fileName"/>.
        /// </summary>
        /// <typeparam name="T">The type of the class to be populated from the serialized file.</typeparam>
        /// <param name="fileLockName">The name of the lock to use when reading the file.</param>
        /// <param name="fileName">The name of the file. A relative name will resolve to the runtime directory.</param>
        /// <returns></returns>
        public static T LoadFromFile <T>(string fileLockName, string fileName) where T : new()
        {
            FileSerializer <T> objSerializer = GetFileSerializer <T>(fileLockName, fileName);

            _log.DebugFormat("loading type instance from file {0}", objSerializer.XmlFile);
            return(objSerializer.LoadObjectFromFile(false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves instance <paramref name="obj"/> of type <typeparamref name="T"/> as XML to <paramref name="fileName"/>.
        /// </summary>
        /// <typeparam name="T">The type of the class to be save to the serialized file.</typeparam>
        /// <param name="obj">Object instance to save.</param>
        /// <param name="fileLockName">The name of the lock to use when writing the file.</param>
        /// <param name="fileName">The name of the file. A relative name will resolve to the runtime directory.</param>
        /// <returns></returns>
        public static void SaveToFile <T>(T obj, string fileLockName, string fileName) where T : new()
        {
            FileSerializer <T> objSerializer = GetFileSerializer <T>(fileLockName, fileName);

            objSerializer.WriteObjectToFile(obj);
        }