// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using System.Runtime.Serialization; using System.Security.Permissions; using System.Windows; namespace ICSharpCode.AvalonEdit.Highlighting.Xshd { /// /// A color in an Xshd file. /// [Serializable] public class XshdColor : XshdElement, ISerializable { /// /// Gets/sets the name. /// public string Name { get; set; } /// /// Gets/sets the foreground brush. /// public HighlightingBrush Foreground { get; set; } /// /// Gets/sets the background brush. /// public HighlightingBrush Background { get; set; } /// /// Gets/sets the font weight. /// public FontWeight? FontWeight { get; set; } /// /// Gets/sets the font style. /// public FontStyle? FontStyle { get; set; } /// /// Gets/Sets the example text that demonstrates where the color is used. /// public string ExampleText { get; set; } /// /// Creates a new XshdColor instance. /// public XshdColor() { } /// /// Deserializes an XshdColor. /// protected XshdColor(SerializationInfo info, StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); this.Name = info.GetString("Name"); this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush)); this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush)); if (info.GetBoolean("HasWeight")) this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight")); if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); this.ExampleText = info.GetString("ExampleText"); } /// /// Serializes this XshdColor instance. /// #if DOTNET4 [System.Security.SecurityCritical] #else [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] #endif public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); info.AddValue("Name", this.Name); info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); info.AddValue("HasWeight", this.FontWeight.HasValue); if (this.FontWeight.HasValue) info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); info.AddValue("HasStyle", this.FontStyle.HasValue); if (this.FontStyle.HasValue) info.AddValue("Style", this.FontStyle.Value.ToString()); info.AddValue("ExampleText", this.ExampleText); } /// public override object AcceptVisitor(IXshdVisitor visitor) { return visitor.VisitColor(this); } } }