Repository navigation
Expand file tree
/
Copy pathCustomFormat.cs
More file actions
87 lines (77 loc) · 2.34 KB
/
Copy pathCustomFormat.cs
File metadata and controls
87 lines (77 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using FastReport.Utils;
namespace FastReport.Format
{
/// <summary>
/// Represents a format that uses the <b>Format</b> string to display values.
/// </summary>
public class CustomFormat : FormatBase
{
#region Fields
private string format;
#endregion
#region Properties
/// <summary>
/// Gets or sets a format string.
/// </summary>
/// <remarks>
/// Default format is "G". For example, if you want to format a date, use the following
/// format string: "MM/dd/yyyy". See the <b>System.String.Format</b> method for list
/// of possible format strings.
/// </remarks>
public string Format
{
get { return format; }
set { format = value; }
}
#endregion
#region Public Methods
/// <inheritdoc/>
public override FormatBase Clone()
{
CustomFormat result = new CustomFormat();
result.Format = Format;
return result;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
CustomFormat f = obj as CustomFormat;
return f != null && Format == f.Format;
}
/// <inheritdoc/>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <inheritdoc/>
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
/// <summary>
/// Initializes a new instance of the <b>CustomFormat</b> class with default settings.
/// </summary>
public CustomFormat()
{
Format = "G";
}
}
}