Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. XML serializition.

XML serializition.

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionlampgraphicsxmljson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3749986
    wrote on last edited by
    #1

    Hello all, i'm making a dynamic light system, that contains scene's. A scene has a lamp (philips livingColor), min 1 max 8, and each lamp has its own platform. The save/edit a scene i am saving all data in the class Lamp (and motor) in a list . The struct: Color_point has string, int and a Color. However, if i want to serialise the class, i wont get a color in the xml. I know this is an private attribute, so i wont get something back. And I already read some more about making a different struc tfor the color. But.. how? See Code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Xml.Serialization;

    namespace Light
    {
    [Serializable()]
    public struct Color_Point
    {
    public string Name;
    public int Time;
    public Color Rgb;

        public Color\_Point(string name, int time, Color rgb)
        {
            Name = name;
            Time = time; //in ms
            Rgb = rgb;
        }
    
    }
    \[Serializable()\]
    public class Lamp
    {
        public int address;
        public Color current\_Color;
        public Color previous\_Color;
        public List<Color\_Point> list = new List<Color\_Point>();
    
        public Lamp()
        {
            address = 0;
        }
    
          
    
        public void setColor(Int32 time, Color rgb, string name)
        {
            int correct\_time = 0;
            if (name != "Fade")
            {
                if (list.Count == 0)
                    list.Add(new Color\_Point(name, 0, rgb));
                else
                {
                    correct\_time = getTime("btnColor" + LastNumber()) + time;
                    
                    list.Add(new Color\_Point(name, correct\_time, rgb));
                    
                }
                }
            else 
                list.Add(new Color\_Point(name, time, rgb));
            
        }
    

    How can i make sure that i also save the Colors?? Thank you!

    D 1 Reply Last reply
    0
    • U User 3749986

      Hello all, i'm making a dynamic light system, that contains scene's. A scene has a lamp (philips livingColor), min 1 max 8, and each lamp has its own platform. The save/edit a scene i am saving all data in the class Lamp (and motor) in a list . The struct: Color_point has string, int and a Color. However, if i want to serialise the class, i wont get a color in the xml. I know this is an private attribute, so i wont get something back. And I already read some more about making a different struc tfor the color. But.. how? See Code:

      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Drawing;
      using System.Collections;
      using System.Collections.Specialized;
      using System.Xml.Serialization;

      namespace Light
      {
      [Serializable()]
      public struct Color_Point
      {
      public string Name;
      public int Time;
      public Color Rgb;

          public Color\_Point(string name, int time, Color rgb)
          {
              Name = name;
              Time = time; //in ms
              Rgb = rgb;
          }
      
      }
      \[Serializable()\]
      public class Lamp
      {
          public int address;
          public Color current\_Color;
          public Color previous\_Color;
          public List<Color\_Point> list = new List<Color\_Point>();
      
          public Lamp()
          {
              address = 0;
          }
      
            
      
          public void setColor(Int32 time, Color rgb, string name)
          {
              int correct\_time = 0;
              if (name != "Fade")
              {
                  if (list.Count == 0)
                      list.Add(new Color\_Point(name, 0, rgb));
                  else
                  {
                      correct\_time = getTime("btnColor" + LastNumber()) + time;
                      
                      list.Add(new Color\_Point(name, correct\_time, rgb));
                      
                  }
                  }
              else 
                  list.Add(new Color\_Point(name, time, rgb));
              
          }
      

      How can i make sure that i also save the Colors?? Thank you!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      An easy way around that is to make the color private and expose it's constituant parts (R, G, B) as pubic properties. A leaner way to do it would be to implement your own custom serializer for your class. See this[^] for a quick explanation and sample.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups