示例#1
0
        /// <summary>
        /// Deserialize string from a file to an object
        /// </summary>
        /// <typeparam name="T">Type of Object that we want to Deserialize into</typeparam>
        /// <param name="path">Path to the file where the json file is stored</param>
        /// <returns>Object of T type deserialized from the path given</returns>
        public T DeserializeFromPath <T>(string path) where T : class
        {
            // String representation of file content
            string content = _fileProcessor.ReadFromFile(path);

            // Deserialize content to our object
            var obj = JsonConvert.DeserializeObject <T>(content);

            return(obj);
        }
示例#2
0
 private void btnReadFile_Click(object sender, EventArgs e)
 {
     try
     {
         if (HorseTipDataValidator.ValidateReadData(fileProcessor.ReadFromFile()))
         {
             HotTips.horseTips = fileProcessor.ReadFromFile();
             rtbDisplay.Clear();
             UpdateList();
         }
         else
         {
             MessageBox.Show("No data in file.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
        public void Test_Read_File_Content()
        {
            #region Prepare
            // Path for existing file
            string path = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())), "file.json");
            #endregion

            #region Act
            var content = _fileProcessor.ReadFromFile(path);
            #endregion

            #region Assert
            Assert.NotEmpty(content);
            #endregion
        }