1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- #nullable disable
5
-
6
4
using DocumentFormat . OpenXml . Framework ;
7
5
using DocumentFormat . OpenXml . Packaging ;
8
6
using System ;
9
7
using System . Collections . Generic ;
10
8
using System . ComponentModel ;
11
9
using System . Diagnostics ;
10
+ using System . Diagnostics . CodeAnalysis ;
12
11
using System . Linq ;
13
12
using System . Text ;
14
13
using System . Xml ;
@@ -32,7 +31,6 @@ internal XmlPath(OpenXmlElement element)
32
31
}
33
32
34
33
PartUri = element . GetPartUri ( ) ;
35
-
36
34
XPath = TryBuildXPath ( GetElements ( element ) , out var namespaces ) ;
37
35
38
36
#pragma warning disable CS0618 // Type or member is obsolete
@@ -64,6 +62,12 @@ internal XmlPath(OpenXmlPart part)
64
62
}
65
63
66
64
PartUri = part . Uri ;
65
+ XPath = string . Empty ;
66
+
67
+ #pragma warning disable CS0618 // Type or member is obsolete
68
+ Namespaces = ReadOnlyWrapper . Instance ;
69
+ NamespacesDefinitions = Cached . Array < string > ( ) ;
70
+ #pragma warning restore CS0618 // Type or member is obsolete
67
71
}
68
72
69
73
/// <summary>
@@ -93,7 +97,7 @@ internal XmlPath(OpenXmlPart part)
93
97
/// </summary>
94
98
/// <param name="element">The OpenXmlElement.</param>
95
99
/// <returns>XmlPath to this element from root element.</returns>
96
- internal static XmlPath GetXPath ( OpenXmlElement element )
100
+ internal static XmlPath ? GetXPath ( OpenXmlElement ? element )
97
101
{
98
102
if ( element is null )
99
103
{
@@ -103,7 +107,7 @@ internal static XmlPath GetXPath(OpenXmlElement element)
103
107
return new XmlPath ( element ) ;
104
108
}
105
109
106
- internal static XmlPath GetXPath ( OpenXmlPart part )
110
+ internal static XmlPath ? GetXPath ( OpenXmlPart ? part )
107
111
{
108
112
if ( part is null )
109
113
{
@@ -113,7 +117,7 @@ internal static XmlPath GetXPath(OpenXmlPart part)
113
117
return new XmlPath ( part ) ;
114
118
}
115
119
116
- private static string TryBuildXPath ( Stack < OpenXmlElement > elements , out XmlNamespaceManager namespaces )
120
+ private static string TryBuildXPath ( Stack < OpenXmlElement > elements , [ MaybeNullWhen ( false ) ] out XmlNamespaceManager namespaces )
117
121
{
118
122
if ( elements . Count == 0 )
119
123
{
@@ -163,7 +167,7 @@ private static string TryBuildXPath(Stack<OpenXmlElement> elements, out XmlNames
163
167
return xpath . ToString ( ) ;
164
168
}
165
169
166
- private static Stack < OpenXmlElement > GetElements ( OpenXmlElement element )
170
+ private static Stack < OpenXmlElement > GetElements ( OpenXmlElement ? element )
167
171
{
168
172
var elements = new Stack < OpenXmlElement > ( ) ;
169
173
@@ -189,9 +193,9 @@ public ReadOnlyWrapper(IXmlNamespaceResolver other)
189
193
190
194
public IDictionary < string , string > GetNamespacesInScope ( XmlNamespaceScope scope ) => _other . GetNamespacesInScope ( scope ) ;
191
195
192
- public string LookupNamespace ( string prefix ) => _other . LookupNamespace ( prefix ) ;
196
+ public string ? LookupNamespace ( string prefix ) => _other . LookupNamespace ( prefix ) ;
193
197
194
- public string LookupPrefix ( string namespaceName ) => _other . LookupPrefix ( namespaceName ) ;
198
+ public string ? LookupPrefix ( string namespaceName ) => _other . LookupPrefix ( namespaceName ) ;
195
199
}
196
200
}
197
201
}
0 commit comments