Example #1
0
        public override object Deserialize(XElement elem, XNamespace overridingNamespace)
        {
            var dsElem = elem.Elements().FirstOrDefault(x => x.Name.LocalName == "NewDataSet");

            if (dsElem == null)
            {
                return(null);
            }

            using (var xr = dsElem.CreateReader())
            {
                var dsType = ReflectionUtils.GetTypeByName("System.Data.DataSet");
                var ds     = Activator.CreateInstance(dsType);
                ReflectionUtils.InvokeMethod(ds, "ReadXml", xr);
                var dsTables      = ReflectionUtils.InvokeGetProperty <object>(ds, "Tables");
                var dsTablesCount = ReflectionUtils.InvokeGetProperty <int>(dsTables, "Count");
                if (dsTablesCount > 0)
                {
                    var dsTablesZero = ReflectionUtils.InvokeIntIndexer <object>(dsTables, "Index", 0);
                    var copyDt       = ReflectionUtils.InvokeMethod(dsTablesZero, "Copy");
                    return(copyDt);
                }
                return(null);
            }
        }
Example #2
0
 public override void Serialize(object obj, XElement elem, XNamespace overridingNamespace)
 {
     using (var xw = elem.CreateWriter())
     {
         var dsType   = ReflectionUtils.GetTypeByName("System.Data.DataSet");
         var ds       = Activator.CreateInstance(dsType);
         var dsTables = ReflectionUtils.InvokeGetProperty <object>(ds, "Tables");
         var dtCopy   = ReflectionUtils.InvokeMethod(obj, "Copy", new object[0]);
         ReflectionUtils.InvokeMethod(dsTables, "Add", dtCopy);
         ReflectionUtils.InvokeMethod(ds, "WriteXml", xw);
     }
 }
Example #3
0
        public override object Deserialize(XElement elem, XNamespace overridingNamespace)
        {
            var child = elem.Elements().FirstOrDefault();

            if (child == null)
            {
                return(null);
            }
            using (var xr = child.CreateReader())
            {
                var dsType = ReflectionUtils.GetTypeByName("System.Data.DataSet");
                var ds     = Activator.CreateInstance(dsType);
                ReflectionUtils.InvokeMethod(ds, "ReadXml", xr);
                return(ds);
            }
        }
Example #4
0
 public override Type Deserialize(XElement elem, XNamespace overridingNamespace)
 {
     return(ReflectionUtils.GetTypeByName(elem.Value));
 }