NanoXLSX.Core 3.2.1
Loading...
Searching...
No Matches
XmlAttribute.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 System.Linq;
10
12{
13 // TODO Set to internal in next major release
17 public struct XmlAttribute
18 {
22 public string Name { get; private set; }
26 public string Value { get; private set; }
30 public bool HasPrefix { get; private set; }
34 public string Prefix { get; private set; }
35
42
43 internal XmlAttribute(string name, string value, string prefix = "")
44 {
45 this.Name = name;
46 this.Value = value;
47 this.Prefix = prefix;
48 HasPrefix = !string.IsNullOrEmpty(prefix);
49 }
50
58 public static XmlAttribute CreateAttribute(string name, string value, string prefix = "")
59 {
60 return new XmlAttribute(name, value, prefix);
61 }
62
69 public static XmlAttribute CreateEmptyAttribute(string name, string prefix = "")
70 {
71 return new XmlAttribute(name, "", prefix);
72 }
73
80 public static XmlAttribute? FindAttribute(string name, HashSet<XmlAttribute> attributes)
81 {
82 if (attributes == null || attributes.Count == 0)
83 {
84 return null;
85 }
86 if (!attributes.Any(a => a.Name == name))
87 {
88 return null;
89 }
90 return attributes.Where(a => a.Name == name).FirstOrDefault();
91 }
92
98 public override bool Equals(object obj)
99 {
100 return obj is XmlAttribute attribute &&
101 Name == attribute.Name &&
102 Value == attribute.Value &&
103 Prefix == attribute.Prefix;
104 }
105
110 public override int GetHashCode()
111 {
112 unchecked
113 {
114 int hashCode = 27885120;
115 hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
116 hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Value);
117 hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Prefix);
118 return hashCode;
119 }
120 }
121 }
122}
Struct representing an internally used XML attribute.
string Prefix
Prefix of the attribute. If not defined, the prefix will be an empty string.
override bool Equals(object obj)
Returns whether two instances are the same.
bool HasPrefix
True if a prefix for the attribute was defined.
static ? XmlAttribute FindAttribute(string name, HashSet< XmlAttribute > attributes)
Method to find an attribute in a given list by attribute name. It is assumed that there are no duplic...
override int GetHashCode()
Gets the hash code of the attribute.
static XmlAttribute CreateAttribute(string name, string value, string prefix="")
Method to create an attribute instance.
static XmlAttribute CreateEmptyAttribute(string name, string prefix="")
Method to create an empty attribute instance.
string Name
Name of the attribute (without prefix).
string Value
Attribute value as string.