NanoXLSX.Formatting 3.0.0
Loading...
Searching...
No Matches
TextRun.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using System.Collections.Generic;
9using NanoXLSX.Styles;
10using NanoXLSX.Utils.Xml;
11
12namespace NanoXLSX.Extensions
13{
17 public class TextRun
18 {
19 private string text;
20
25 public string Text
26 {
27 get { return text; }
28 set
29 {
30 if (value == null)
31 {
32 throw new Exceptions.FormatException("The text of a text run cannot be null");
33 }
34 text = XmlUtils.SanitizeXmlValue(value); ;
35 }
36 }
37
40 public Font FontStyle { get; set; }
41
48 public TextRun(string text, Font fontStyle = null)
49 {
50 Text = text;
51 FontStyle = fontStyle;
52 }
53
58 public TextRun Copy()
59 {
60 return new TextRun(this.Text, this.FontStyle?.CopyFont());
61 }
62
68 public override bool Equals(object obj)
69 {
70 if (!(obj is TextRun run))
71 return false;
72
73 return text == run.text &&
74 ((FontStyle == null && run.FontStyle == null) ||
75 (FontStyle != null && FontStyle.Equals(run.FontStyle)));
76 }
77
78
83 public override int GetHashCode()
84 {
85 var hashCode = 1049193379;
86 hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(text);
87 hashCode = hashCode * -1521134295 + EqualityComparer<Font>.Default.GetHashCode(FontStyle);
88 return hashCode;
89 }
90 }
91}
string Text
Plain text of the run.
Definition TextRun.cs:26
override bool Equals(object obj)
Equals override to compare text runs.
Definition TextRun.cs:68
override int GetHashCode()
HashCode override for text runs.
Definition TextRun.cs:83
TextRun Copy()
Creates a copy of the current text run.
Definition TextRun.cs:58
Font FontStyle
Font style applied to the text run.
Definition TextRun.cs:40
TextRun(string text, Font fontStyle=null)
Constructor to create a text run with optional inline style.
Definition TextRun.cs:48