Ejemplo n.º 1
0
        /// <summary>
        /// Deserializes from file.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="file">The file.</param>
        /// <returns>System.Object.</returns>
        /// <inheritdoc />
        public object DeserializeFromFile(Type type, string fullFilePath)
        {
            CanDeserialize(type, true);
            var a = new FileObject(fullFilePath);

            return(DeserializeFromStream(a.ReadFileToStream(), type));
        }
Ejemplo n.º 2
0
        public IEnumerable <T> DeserializeListFromFile <T>(string fullFilePath) where T : class
        {
            //var doc = XDocument.Load(fullFilePath);
            //var jsonText = JsonConvert.SerializeXNode(doc);
            //return JsonConvert.DeserializeObject<List<T>>(jsonText);


            CanDeserialize(typeof(T), true);
            var a    = new FileObject(fullFilePath);
            var data = DeserializeFromStream(a.ReadFileToStream(), typeof(List <T>));

            return((IEnumerable <T>)data);
            //  var data2 = DeserializeFromFile(typeof(T), fullFilePath);
            //    var data3 = DeserializeFromFile(typeof(List<T>), fullFilePath);



            // return data as IEnumerable<T>;
            //var t = typeof(T);
            //if(t.IsInterface)
            //    t = t.GetType();
            ////////var a = new FileObject(fullFilePath);
            ////////return DeserializeFromStream(a.ReadFileToStream(), t) as IEnumerable<T>;

            ////////var doc = XDocument.Load(fullFilePath);
            ////////var jsonText = JsonConvert.SerializeXNode(doc);
            ////////if (typeof(T).IsInterface)
            ////////{
            ////////    var badTest = typeof(T);
            ////////    var test = typeof(T).GetType();
            ////////    return JsonConvert.DeserializeObject(jsonText,test) as IEnumerable<T>;
            ////////}


            ////////return JsonConvert.DeserializeObject<IEnumerable<T>>(jsonText);


            //var context = new XmlSerializationContext(Settings);
            //using (var fileStream = new FileObject(fullFilePath).ReadFileToStream())
            //{
            //    using (var reader = new XmlTextReader(fileStream))
            //    {
            //        yield return context.Deserialize(reader, typeof(IEnumerable<T>)) as T;
            //    }

            //}



            //    var doc = XDocument.Load(fullFilePath);
            //    using (var reader = XmlReader.Create(fullFilePath, Settings.GetReaderSettings()))
            //    {
            //        var xmlSerializer = new XmlSerializer(typeof(IEnumerable<T>));
            //        return (IEnumerable<T>)xmlSerializer.Deserialize(reader);
            //    }
        }
        /// <inheritdoc />
        public object DeserializeFromFile(Type type, string fullFilePath)
        {
            type.IsNullThrow(nameof(type));
            fullFilePath.IsNullThrow(nameof(fullFilePath));

            var tempFile = new FileObject(fullFilePath);

            using (var stream = tempFile.ReadFileToStream())
            {
                return(DeserializeFromStream(stream, type));
            }
        }