using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using FastReport.Utils;
namespace FastReport.Format
{
///
/// Represents a format that uses the Format string to display values.
///
public class CustomFormat : FormatBase
{
#region Fields
private string format;
#endregion
#region Properties
///
/// Gets or sets a format string.
///
///
/// Default format is "G". For example, if you want to format a date, use the following
/// format string: "MM/dd/yyyy". See the System.String.Format method for list
/// of possible format strings.
///
public string Format
{
get { return format; }
set { format = value; }
}
#endregion
#region Public Methods
///
public override FormatBase Clone()
{
CustomFormat result = new CustomFormat();
result.Format = Format;
return result;
}
///
public override bool Equals(object obj)
{
CustomFormat f = obj as CustomFormat;
return f != null && Format == f.Format;
}
///
public override int GetHashCode()
{
return base.GetHashCode();
}
///
public override string FormatValue(object value)
{
if (value is Variant)
value = ((Variant)value).Value;
return String.Format("{0:" + Format + "}", value);
}
internal override string GetSampleValue()
{
return "";
}
internal override void Serialize(FRWriter writer, string prefix, FormatBase format)
{
base.Serialize(writer, prefix, format);
CustomFormat c = format as CustomFormat;
if (c == null || Format != c.Format)
writer.WriteStr(prefix + "Format", Format);
}
#endregion
///
/// Initializes a new instance of the CustomFormat class with default settings.
///
public CustomFormat()
{
Format = "G";
}
}
}