NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
StyleRepository.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 © 2025
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;
9
10namespace NanoXLSX.Styles
11{
16 public class StyleRepository
17 {
18 private readonly object lockObject = new object();
19
20 private static StyleRepository instance;
21
25 public static StyleRepository Instance
26 {
27 get
28 {
29 instance = instance ?? new StyleRepository();
30 return instance;
31 }
32 }
33
34 private Dictionary<int, Style> styles;
35
39 internal bool ImportInProgress { get; set; }
40
44 public Dictionary<int, Style> Styles { get => styles; }
45
49 private StyleRepository()
50 {
51 styles = new Dictionary<int, Style>();
52 }
53
59 public Style AddStyle(Style style)
60 {
61 lock (lockObject)
62 {
63 if (style == null)
64 {
65 return null;
66 }
67 int hashCode = style.GetHashCode();
68 if (!styles.TryGetValue(hashCode, out var value))
69 {
70 value = style;
71 styles.Add(hashCode, value);
72 }
73 return value;
74 }
75 }
76
82 public void FlushStyles()
83 {
84 styles.Clear();
85 }
86
87 }
88}
Class to manage all styles at runtime, before writing XLSX files. The main purpose is deduplication a...
static StyleRepository Instance
Gets the singleton instance of the repository.
Style AddStyle(Style style)
Adds a style to the repository and returns the actual reference.
void FlushStyles()
Empties the static repository.
Dictionary< int, Style > Styles
Gets the currently managed styles of the repository.
Class representing a Style with sub classes within a style sheet. An instance of this class is only a...
Definition Style.cs:18
override int GetHashCode()
Returns a hash code for this instance.
Definition Style.cs:183