예제 #1
0
        public override void Serialize(object obj, XElement elem, XNamespace overridingNamespace)
        {
            var objectType = obj.GetType();

            if (objectType.FullName != TypeName)
            {
                throw new ArgumentException("Object type does not match the provided typename", "obj");
            }

            var isKnownColor = ReflectionUtils.InvokeGetProperty <bool>(obj, "IsKnownColor");

            if (isKnownColor)
            {
                var colorName = ReflectionUtils.InvokeGetProperty <string>(obj, "Name");
                elem.Value = colorName;
            }
            else
            {
                var a = ReflectionUtils.InvokeGetProperty <byte>(obj, "A");
                var r = ReflectionUtils.InvokeGetProperty <byte>(obj, "R");
                var g = ReflectionUtils.InvokeGetProperty <byte>(obj, "G");
                var b = ReflectionUtils.InvokeGetProperty <byte>(obj, "B");
                elem.Add(
                    new XElement(this.GetXName("A", overridingNamespace), a),
                    new XElement(this.GetXName("R", overridingNamespace), r),
                    new XElement(this.GetXName("G", overridingNamespace), g),
                    new XElement(this.GetXName("B", overridingNamespace), b));
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
        public override void Serialize(object obj, XElement elem, XNamespace overridingNamespace)
        {
            Type objectType = obj.GetType();

            if (objectType.FullName != TypeName)
            {
                throw new ArgumentException("Object type does not match the provided typename", "obj");
            }

            elem.Value = ReflectionUtils.InvokeGetProperty <string>(obj, "FullName");
        }
예제 #4
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);
     }
 }
        public override void Serialize(object obj, XElement elem, XNamespace overridingNamespace)
        {
            var objectType = obj.GetType();

            if (objectType.FullName != TypeName)
            {
                throw new ArgumentException("Object type does not match the provided typename", "obj");
            }

            var left   = ReflectionUtils.InvokeGetProperty <int>(obj, "Left");
            var top    = ReflectionUtils.InvokeGetProperty <int>(obj, "Top");
            var width  = ReflectionUtils.InvokeGetProperty <int>(obj, "Width");
            var height = ReflectionUtils.InvokeGetProperty <int>(obj, "Height");

            elem.Add(
                new XElement(this.GetXName("Left", overridingNamespace), left),
                new XElement(this.GetXName("Top", overridingNamespace), top),
                new XElement(this.GetXName("Width", overridingNamespace), width),
                new XElement(this.GetXName("Height", overridingNamespace), height));
        }