Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CngProperty.cs
Go to the documentation of this file.
3
5
6public struct CngProperty : IEquatable<CngProperty>
7{
8 private readonly byte[] _value;
9
10 private int? _lazyHashCode;
11
12 public string Name { get; private set; }
13
14 public CngPropertyOptions Options { get; private set; }
15
16 public CngProperty(string name, byte[]? value, CngPropertyOptions options)
17 {
18 this = default(CngProperty);
19 if (name == null)
20 {
21 throw new ArgumentNullException("name");
22 }
23 Name = name;
25 _lazyHashCode = null;
26 _value = value?.CloneByteArray();
27 }
28
29 public byte[]? GetValue()
30 {
31 if (_value != null)
32 {
33 return _value.CloneByteArray();
34 }
35 return null;
36 }
37
38 public override bool Equals([NotNullWhen(true)] object? obj)
39 {
40 if (obj is CngProperty)
41 {
42 return Equals((CngProperty)obj);
43 }
44 return false;
45 }
46
48 {
49 if (!string.Equals(Name, other.Name, StringComparison.Ordinal))
50 {
51 return false;
52 }
53 if (Options != other.Options)
54 {
55 return false;
56 }
57 if (_value == null)
58 {
59 return other._value == null;
60 }
61 if (other._value == null)
62 {
63 return false;
64 }
65 if (_value.Length != other._value.Length)
66 {
67 return false;
68 }
69 for (int i = 0; i < _value.Length; i++)
70 {
71 if (_value[i] != other._value[i])
72 {
73 return false;
74 }
75 }
76 return true;
77 }
78
79 public override int GetHashCode()
80 {
81 if (!_lazyHashCode.HasValue)
82 {
83 int num = Name.GetHashCode() ^ Options.GetHashCode();
84 if (_value != null)
85 {
86 for (int i = 0; i < _value.Length; i++)
87 {
88 int num2 = _value[i] << i % 4 * 8;
89 num ^= num2;
90 }
91 }
92 _lazyHashCode = num;
93 }
94 return _lazyHashCode.Value;
95 }
96
97 public static bool operator ==(CngProperty left, CngProperty right)
98 {
99 return left.Equals(right);
100 }
101
102 public static bool operator !=(CngProperty left, CngProperty right)
103 {
104 return !left.Equals(right);
105 }
106
107 internal byte[] GetValueWithoutCopying()
108 {
109 return _value;
110 }
111}
override bool Equals([NotNullWhen(true)] object? obj)
static bool operator!=(CngProperty left, CngProperty right)
static bool operator==(CngProperty left, CngProperty right)
CngProperty(string name, byte[]? value, CngPropertyOptions options)