Advertisement
MBrendecke

SColor

Feb 7th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.ComponentModel;
  2. using System.Runtime.Serialization;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5.  
  6. namespace System.Drawing
  7. {
  8.     [Serializable]
  9.     public class SColor : ISerializable
  10.     {
  11.         #region Eigenschaften
  12.  
  13.         [XmlIgnore]
  14.         public Color Color { get; set; }
  15.  
  16.         [Browsable(false)]
  17.         [XmlElement]
  18.         public int XmlColor {
  19.             get { return Color != Color.Empty ? Color.ToArgb() : 0; }
  20.             set { Color = Color.FromArgb(value); }
  21.         }
  22.  
  23.         #endregion Eigenschaften
  24.  
  25.         #region Konstruktoren
  26.  
  27.         public SColor()
  28.         {
  29.             Color = Color.Empty;
  30.         }
  31.  
  32.         public SColor(Color color)
  33.         {
  34.             Color = color;
  35.         }
  36.  
  37.         public SColor(SerializationInfo info, StreamingContext context)
  38.         {
  39.             Color = Color.FromArgb((int)info.GetValue(nameof(XmlColor), typeof(int)));
  40.         }
  41.  
  42.         #endregion Konstruktoren
  43.  
  44.         #region ISerializable
  45.  
  46.         public void GetObjectData(SerializationInfo info, StreamingContext context)
  47.         {
  48.             info.AddValue(nameof(XmlColor), Color.ToArgb());
  49.         }
  50.  
  51.         #endregion ISerializable
  52.  
  53.         #region Implizite Konvertierung
  54.  
  55.         public static implicit operator Color(SColor color)
  56.         {
  57.             return color != null ? color.Color : Color.Empty;
  58.         }
  59.  
  60.         public static implicit operator SColor(Color color)
  61.         {
  62.             return new SColor(color);
  63.         }
  64.  
  65.         #endregion Implizite Konvertierung
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement