Skip to content

Commit 5c7c16c

Browse files
committed
Add XML Serialization classes
1 parent 549da90 commit 5c7c16c

27 files changed

+713
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
// This file is used by Code Analysis to maintain SuppressMessage
3+
// attributes that are applied to this project.
4+
// Project-level suppressions either have no target or are given
5+
// a specific target and scoped to a namespace, type, member, etc.
6+
7+
using System.Diagnostics.CodeAnalysis;
8+
9+
[assembly: SuppressMessage(
10+
"Design",
11+
"CA1002: Do not expose generic lists",
12+
Scope = "namespaceAndDescendants",
13+
Target = "~N:ClangSharp.XML",
14+
Justification = nameof(System.Xml.Serialization)
15+
)]
16+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Xml.Serialization;
6+
7+
namespace ClangSharp.XML;
8+
9+
[XmlType]
10+
[XmlRoot("bindings")]
11+
public sealed class BindingsElement
12+
{
13+
[XmlElement("comment")]
14+
public string? HeaderText { get; init; }
15+
16+
[XmlElement("namespace")]
17+
public List<NamespaceElement> Namespaces { get; } = [];
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Collections.Generic;
4+
using System.Xml;
5+
using System.Xml.Serialization;
6+
7+
namespace ClangSharp.XML;
8+
9+
[XmlType]
10+
public sealed class CSharpCodeElement
11+
{
12+
[XmlText]
13+
[XmlAnyElement]
14+
public List<XmlNode> Segments { get; } = [];
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Xml.Serialization;
4+
5+
namespace ClangSharp.XML;
6+
7+
[XmlType]
8+
public class ConstantDescElement : FieldDescElement { }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Xml.Serialization;
4+
5+
namespace ClangSharp.XML;
6+
7+
[XmlType]
8+
public class DelegateDescElement : FunctionOrDelegateDescElement { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Diagnostics;
4+
using System.Xml.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
[XmlType]
9+
[DebuggerDisplay($"{{{nameof(Name)},nq}}")]
10+
public class EnumConstantDeclElement : FieldDescElement { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Collections.Generic;
4+
using System.Xml.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
[XmlType]
9+
public class EnumDescElement : NamedAccessDescElement
10+
{
11+
[XmlElement("attribute")]
12+
public List<string> Attributes { get; } = [];
13+
14+
[XmlElement("type")]
15+
public required string TypeName { get; init; }
16+
17+
[XmlElement("enumerator")]
18+
public List<EnumConstantDeclElement> Enumerators { get; } = [];
19+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Globalization;
6+
using System.Xml.Serialization;
7+
8+
namespace ClangSharp.XML;
9+
10+
[XmlType]
11+
[DebuggerDisplay($"{{{nameof(AccessSpecifier)},nq}} {{{nameof(Type)}}} {{{nameof(Name)},nq}}")]
12+
public class FieldDescElement : NamedAccessDescElement
13+
{
14+
[XmlAttribute("inherited")]
15+
public string? InheritedFrom { get; init; }
16+
17+
[XmlAttribute("offset")]
18+
public string? OffsetValue { get; init; }
19+
20+
[XmlIgnore]
21+
public int? Offset
22+
{
23+
get
24+
{
25+
return int.TryParse(
26+
OffsetValue,
27+
CultureInfo.InvariantCulture,
28+
out var offset
29+
) ? offset : null;
30+
}
31+
32+
init
33+
{
34+
OffsetValue = value.HasValue
35+
? value.Value.ToString(CultureInfo.InvariantCulture)
36+
: null;
37+
}
38+
}
39+
40+
[XmlElement("attribute")]
41+
public List<string> Attributes { get; } = [];
42+
43+
[XmlElement("type")]
44+
public required FieldTypeElement Type { get; init; }
45+
46+
[XmlElement("value")]
47+
public ValueDescValueElement? Initializer { get; init; }
48+
49+
[XmlElement("get")]
50+
public PropertyAccessorElement? Getter { get; init; }
51+
52+
[XmlElement("set")]
53+
public PropertyAccessorElement? Setter { get; init; }
54+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Xml.Serialization;
4+
5+
namespace ClangSharp.XML;
6+
7+
[XmlType]
8+
public class FieldTypeElement : TypeWithNativeTypeNameElement
9+
{
10+
[XmlAttribute("count")]
11+
public string? Count { get; init; }
12+
13+
[XmlAttribute("fixed")]
14+
public string? FixedName { get; init; }
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System.Xml.Serialization;
4+
5+
namespace ClangSharp.XML;
6+
7+
[XmlType]
8+
public class FunctionBodyElement
9+
{
10+
[XmlElement("code")]
11+
public CSharpCodeElement? Code { get; init; }
12+
}

0 commit comments

Comments
 (0)