CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Aug 2017
    Posts
    36

    Re: Saving XML Root Attributes

    Code:
    [XmlRootAttribute("Customer", Namespace="", IsNullable=false)]
    public class Customer
    {
        private Bitmap picture;
    
        public Customer()
        {
        }
    
        [XmlAttributeAttribute(DataType="date")]
        public System.DateTime DateTimeValue;
    
        public int CustomerID;
        public string CustomerName;
        public int Age;
    
        [XmlIgnoreAttribute()]
        public bool CustomerPaid;
    
        [XmlIgnoreAttribute()]
        public Bitmap Picture
        {
            get { return picture; }
            set { picture = value; }
        }
    
     .
        [XmlElementAttribute("Picture")]
        public byte[] PictureByteArray
        {
            get 
            { 
                if (picture != null)
                {
                    TypeConverter BitmapConverter = 
                         TypeDescriptor.GetConverter(picture.GetType());
                    return (byte[]) 
                         BitmapConverter.ConvertTo(picture, typeof(byte[]));
                }
                else
                    return null;
            }
            
            set 
            { 
                if (value != null)
                    picture = new Bitmap(new MemoryStream(value)); 
                else
                    picture = null; 
            }
        }
    
        [XmlArray ("Hobbies"), XmlArrayItem("Hobby", typeof(string))]
        public System.Collections.ArrayList Hobbies = 
               new System.Collections.ArrayList();
    
        [XmlArray ("EmailAddresses"), 
         XmlArrayItem("EmailAddress", typeof(EmailAddress))]
        public System.Collections.ArrayList EmailAddresses = 
               new System.Collections.ArrayList();
    }
    Last edited by 2kaud; September 2nd, 2017 at 02:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured