FormatBase.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. namespace FastReport.Format
  7. {
  8. /// <summary>
  9. /// Base class for all formats.
  10. /// </summary>
  11. /// <remarks>
  12. /// The format is used to format expression value in a <see cref="TextObject"/> object.
  13. /// </remarks>
  14. [TypeConverter(typeof(FastReport.TypeConverters.FormatConverter))]
  15. public abstract class FormatBase : IFRSerializable
  16. {
  17. #region Properties
  18. /// <summary>
  19. /// Gets the short format name (e.g. without a "Format" suffix).
  20. /// </summary>
  21. [Browsable(false)]
  22. public string Name
  23. {
  24. get { return GetType().Name.Replace("Format", ""); }
  25. }
  26. #endregion
  27. #region Public Methods
  28. /// <summary>
  29. /// Creates exact copy of this format.
  30. /// </summary>
  31. /// <returns>The copy of this format.</returns>
  32. public abstract FormatBase Clone();
  33. /// <summary>
  34. /// Formats the specified value.
  35. /// </summary>
  36. /// <param name="value">The value to format.</param>
  37. /// <returns>The string that represents the formatted value.</returns>
  38. public abstract string FormatValue(object value);
  39. internal abstract string GetSampleValue();
  40. internal virtual void Serialize(FRWriter writer, string prefix, FormatBase format)
  41. {
  42. if (format.GetType() != GetType())
  43. writer.WriteStr("Format", Name);
  44. }
  45. /// <inheritdoc/>
  46. public void Serialize(FRWriter writer)
  47. {
  48. writer.ItemName = GetType().Name;
  49. Serialize(writer, "", writer.DiffObject as FormatBase);
  50. }
  51. /// <inheritdoc/>
  52. public void Deserialize(FRReader reader)
  53. {
  54. reader.ReadProperties(this);
  55. }
  56. #endregion
  57. }
  58. }