Beispiel #1
0
        protected static List <T> GetObjectFromFileXml <T>(string fileName)
        {
            List <T> retval = new List <T>();

            using (StreamReader reader =
                       new StreamReader(HelperBase.GetDataFileFullPath(fileName)))
            {
                retval =
                    (List <T>) new XmlSerializer(typeof(List <T>)).Deserialize(reader);
            }
            return(retval);
        }
Beispiel #2
0
 private static List <ContactData> GetContactsFromFileCsv()
 {
     if (null == _contactsFromFile)
     {
         _contactsFromFile = new List <ContactData>();
         var engine = new FileHelperEngine <ContactDataCsv>();
         var contactsFromFileCsv =
             new List <ContactDataCsv>(engine.ReadFile(HelperBase.GetDataFileFullPath("Contacts.csv")));
         foreach (var contactDataCsv in contactsFromFileCsv)
         {
             _contactsFromFile.Add(contactDataCsv.ContactData());
         }
     }
     return(_contactsFromFile);
 }
Beispiel #3
0
        protected static List <T> GetObjectFromFileJson <T>(string fileName)
        {
            List <T> retval = new List <T>();

            using (StreamReader reader =
                       new StreamReader(HelperBase.GetDataFileFullPath(fileName)))
            {
                string jsonDataRaw = reader.ReadToEnd();
                JArray deserialisedJsonContactData = (JArray)JsonConvert.DeserializeObject(jsonDataRaw);
                foreach (var contactData in deserialisedJsonContactData)
                {
                    retval.Add(contactData.ToObject <T>());
                }
            }

            return(retval);
        }