using System; using System.Collections.Generic; using System.Text; using FastReport.Utils; namespace FastReport.Format { /// /// Defines how boolean values are formatted and displayed. /// public class BooleanFormat : FormatBase { #region Fields private string falseText; private string trueText; #endregion #region Properties /// /// Gets or sets a string that will be displayed if value is false. /// public string FalseText { get { return falseText; } set { falseText = value; } } /// /// Gets or sets a string that will be displayed if value is true. /// public string TrueText { get { return trueText; } set { trueText = value; } } #endregion #region Public Methods /// public override FormatBase Clone() { BooleanFormat result = new BooleanFormat(); result.FalseText = FalseText; result.TrueText = TrueText; return result; } /// public override bool Equals(object obj) { BooleanFormat f = obj as BooleanFormat; return f != null && FalseText == f.FalseText && TrueText == f.TrueText; } /// public override int GetHashCode() { return base.GetHashCode(); } /// public override string FormatValue(object value) { if (value is Variant) value = ((Variant)value).Value; if (value is bool && (bool)value == false) return FalseText; if (value is bool && (bool)value == true) return TrueText; return value.ToString(); } internal override string GetSampleValue() { return FormatValue(false); } internal override void Serialize(FRWriter writer, string prefix, FormatBase format) { base.Serialize(writer, prefix, format); BooleanFormat c = format as BooleanFormat; if (c == null || TrueText != c.TrueText) writer.WriteStr(prefix + "TrueText", TrueText); if (c == null || FalseText != c.FalseText) writer.WriteStr(prefix + "FalseText", FalseText); } #endregion /// /// Initializes a new instance of the BooleanFormat class with default settings. /// public BooleanFormat() { FalseText = "False"; TrueText = "True"; } } }