Skip to content

Commit da0fdaf

Browse files
authored
Move OpenXml element, reader, and writers to own files (#340)
1 parent b5870a0 commit da0fdaf

39 files changed

+3444
-3322
lines changed

DocumentFormat.OpenXml/src/ofapi/SchemaInfoAttribute.cs renamed to DocumentFormat.OpenXml/ChildElementInfoAttribute.cs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,6 @@
55

66
namespace DocumentFormat.OpenXml
77
{
8-
/// <summary>
9-
/// Defines the attribute which is used to decorate a property for its corresponding attribute information.
10-
/// </summary>
11-
[AttributeUsage(AttributeTargets.Property)]
12-
public sealed class SchemaAttrAttribute : Attribute
13-
{
14-
//string _type;
15-
private string _tag;
16-
private byte _nsId;
17-
18-
/// <summary>
19-
/// Initializes a new instance of the SchemaAttrAttribute.
20-
/// </summary>
21-
/// <param name="nsId">Specifies the Namespace Id of the schema attribute.</param>
22-
/// <param name="tag">Specifies the Tag name of the schema attribute.</param>
23-
public SchemaAttrAttribute(byte nsId, string tag)
24-
{
25-
if (string.IsNullOrEmpty(tag))
26-
{
27-
throw new ArgumentNullException(nameof(tag));
28-
}
29-
30-
_nsId = nsId;
31-
_tag = tag;
32-
}
33-
34-
/// <summary>
35-
/// Gets/Sets the Tag name of the schema attribute.
36-
/// </summary>
37-
public string Tag
38-
{
39-
get { return _tag; }
40-
//set { _tag = value; }
41-
}
42-
43-
/// <summary>
44-
/// Gets the Namespace Uri of the schema attribute.
45-
/// </summary>
46-
public string NamespaceUri
47-
{
48-
get
49-
{
50-
return NamespaceIdMap.GetNamespaceUri(_nsId);
51-
}
52-
}
53-
}
54-
558
/// <summary>
569
/// Defines the attribute which is used to decorate a class for type of the possible child elements.
5710
/// </summary>

DocumentFormat.OpenXml/src/ofapi/DocumentTypeDetector.cs renamed to DocumentFormat.OpenXml/DocumentTypeDetector.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66

77
namespace DocumentFormat.OpenXml
88
{
9-
/// <summary>
10-
/// Open XML document type.
11-
/// </summary>
12-
internal enum OpenXmlDocumentType
13-
{
14-
Invalid,
15-
Wordprocessing,
16-
Spreadsheet,
17-
Presentation,
18-
}
19-
209
/// <summary>
2110
/// Detector for Open XML document.
2211
/// </summary>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace DocumentFormat.OpenXml
7+
{
8+
/// <summary>
9+
/// Represents arguments for element events.
10+
/// </summary>
11+
public class ElementEventArgs : EventArgs
12+
{
13+
private OpenXmlElement _element;
14+
private OpenXmlElement _parentElement;
15+
16+
/// <summary>
17+
/// Initializes a new instance of the ElementEventArgs class using the
18+
/// supplied elements.
19+
/// </summary>
20+
/// <param name="element">
21+
/// The element that caused the event.
22+
/// </param>
23+
/// <param name="parentElement">
24+
/// The parent element of the element that caused the event.
25+
/// </param>
26+
public ElementEventArgs(OpenXmlElement element, OpenXmlElement parentElement)
27+
{
28+
this._element = element;
29+
this._parentElement = parentElement;
30+
}
31+
32+
/// <summary>
33+
/// Gets the element that caused the event.
34+
/// </summary>
35+
public OpenXmlElement Element
36+
{
37+
get { return this._element; }
38+
}
39+
40+
/// <summary>
41+
/// Gets the parent element of the element that caused the event.
42+
/// </summary>
43+
public OpenXmlElement ParentElement
44+
{
45+
get { return this._parentElement; }
46+
}
47+
}
48+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace DocumentFormat.OpenXml
5+
{
6+
internal enum ElementState
7+
{
8+
Null,
9+
Start,
10+
End,
11+
LeafStart,
12+
LeafEnd,
13+
LoadEnd,
14+
MiscNode,
15+
EOF
16+
}
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
namespace DocumentFormat.OpenXml
8+
{
9+
internal sealed class EmptyElementList : OpenXmlElementList
10+
{
11+
private static readonly EmptyElementList _EmptyElementList = new EmptyElementList();
12+
13+
private EmptyElementList()
14+
{
15+
}
16+
17+
/// <summary>
18+
/// Static singleton.
19+
/// </summary>
20+
internal static EmptyElementList EmptyElementListSingleton
21+
{
22+
get
23+
{
24+
return _EmptyElementList;
25+
}
26+
}
27+
28+
public override OpenXmlElement GetItem(int index)
29+
{
30+
throw new ArgumentOutOfRangeException(nameof(index));
31+
}
32+
33+
public override int Count
34+
{
35+
get { return 0; }
36+
}
37+
38+
public override IEnumerator<OpenXmlElement> GetEnumerator()
39+
{
40+
return EmptyEnumerator<OpenXmlElement>.EmptyEnumeratorSingleton;
41+
}
42+
}
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace DocumentFormat.OpenXml
7+
{
8+
internal class EmptyEnumerable<T> : IEnumerable<T>
9+
{
10+
private static readonly EmptyEnumerable<T> _dummy = new EmptyEnumerable<T>();
11+
12+
#region IEnumerable<KeyValuePair<string,string>> Members
13+
14+
public IEnumerator<T> GetEnumerator()
15+
{
16+
return EmptyEnumerator<T>.EmptyEnumeratorSingleton;
17+
}
18+
19+
#endregion
20+
21+
#region IEnumerable Members
22+
23+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
24+
{
25+
return EmptyEnumerator<T>.EmptyEnumeratorSingleton;
26+
}
27+
28+
#endregion
29+
30+
private EmptyEnumerable() { }
31+
32+
public static EmptyEnumerable<T> EmptyEnumerableSingleton
33+
{
34+
get
35+
{
36+
return _dummy;
37+
}
38+
}
39+
}
40+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
namespace DocumentFormat.OpenXml
8+
{
9+
/// <summary>
10+
/// Empty Enumerator.
11+
/// </summary>
12+
internal sealed class EmptyEnumerator<T> : IEnumerator<T>
13+
{
14+
private static readonly IEnumerator<T> _EmptyEnumerator = new EmptyEnumerator<T>();
15+
16+
private EmptyEnumerator()
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Static singleton.
22+
/// </summary>
23+
internal static IEnumerator<T> EmptyEnumeratorSingleton
24+
{
25+
get
26+
{
27+
return _EmptyEnumerator;
28+
}
29+
}
30+
31+
#region IEnumerator<OpenXmlElement> Members
32+
33+
public T Current
34+
{
35+
get
36+
{
37+
throw new InvalidOperationException(ExceptionMessages.EmptyCollection);
38+
}
39+
}
40+
41+
#endregion
42+
43+
#region IEnumerator Members
44+
45+
object System.Collections.IEnumerator.Current
46+
{
47+
get
48+
{
49+
return this.Current;
50+
}
51+
}
52+
53+
public bool MoveNext()
54+
{
55+
return false;
56+
}
57+
58+
public void Reset()
59+
{
60+
}
61+
62+
#endregion
63+
64+
#region IDisposable Members
65+
66+
public void Dispose()
67+
{
68+
}
69+
70+
#endregion
71+
72+
}
73+
}
File renamed without changes.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
namespace DocumentFormat.OpenXml
8+
{
9+
/// <summary>
10+
/// Implements OpenXmlElementList.
11+
/// </summary>
12+
internal class OpenXmlChildElements : OpenXmlElementList
13+
{
14+
private OpenXmlElement _container;
15+
16+
public OpenXmlChildElements(OpenXmlElement container)
17+
{
18+
this._container = container;
19+
}
20+
21+
public override IEnumerator<OpenXmlElement> GetEnumerator()
22+
{
23+
if (this._container.HasChildren && this._container.FirstChild != null)
24+
{
25+
for ( OpenXmlElement element = this._container.FirstChild;
26+
element != null;
27+
element = element.NextSibling() )
28+
{
29+
yield return element;
30+
}
31+
}
32+
else
33+
{
34+
yield break;
35+
}
36+
}
37+
38+
public override OpenXmlElement GetItem(int index)
39+
{
40+
if (this._container.HasChildren)
41+
{
42+
for (OpenXmlElement element = this._container.FirstChild;
43+
element != null;
44+
element = element.NextSibling())
45+
{
46+
if (index == 0)
47+
{
48+
return element;
49+
}
50+
index--;
51+
}
52+
}
53+
// return null;
54+
throw new ArgumentOutOfRangeException(nameof(index));
55+
}
56+
57+
public override int Count
58+
{
59+
get
60+
{
61+
int num = 0;
62+
if (this._container.HasChildren)
63+
{
64+
for (OpenXmlElement element = this._container.FirstChild;
65+
element != null;
66+
element = element.NextSibling())
67+
{
68+
num++;
69+
}
70+
}
71+
return num;
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)