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+
}
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 FunctionDescElement : FunctionOrDelegateDescElement
10+
{
11+
[XmlElement("init")]
12+
public List<TypeInitializationExpressionElement> TypeInitializationExpressions { get; } = [];
13+
14+
[XmlElement("body")]
15+
public FunctionBodyElement? BlockBody { get; init; }
16+
17+
[XmlElement("code")]
18+
public CSharpCodeElement? ExpressionBody { get; init; }
19+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.ComponentModel;
5+
using System.Globalization;
6+
using System.Xml.Serialization;
7+
8+
namespace ClangSharp.XML;
9+
10+
[XmlType]
11+
public abstract class FunctionOrDelegateDescElement : NamedAccessDescElement
12+
{
13+
[XmlAttribute("lib")]
14+
public string? LibraryPath { get; init; }
15+
16+
[XmlAttribute("convention")]
17+
public string? CallingConvention { get; init; }
18+
19+
[XmlAttribute("entrypoint")]
20+
public string? EntryPoint { get; init; }
21+
22+
[XmlAttribute("setlasterror")]
23+
public bool SetLastError { get; init; }
24+
25+
[XmlIgnore]
26+
[EditorBrowsable(EditorBrowsableState.Never)]
27+
public bool SetLastErrorSpecified => SetLastError;
28+
29+
[XmlAttribute("static")]
30+
public bool IsStatic { get; init; }
31+
32+
[XmlIgnore]
33+
[EditorBrowsable(EditorBrowsableState.Never)]
34+
public bool IsStaticSpecified => IsStatic;
35+
36+
[XmlAttribute("unsafe")]
37+
public bool IsUnsafe { get; init; }
38+
39+
[XmlIgnore]
40+
[EditorBrowsable(EditorBrowsableState.Never)]
41+
public bool IsUnsafeSpecified => IsUnsafe;
42+
43+
[XmlAttribute("vtblindex")]
44+
[EditorBrowsable(EditorBrowsableState.Never)]
45+
public string? VtblIndexValue { get; init; }
46+
47+
[XmlIgnore]
48+
public long? VtblIndex
49+
{
50+
get
51+
{
52+
return !string.IsNullOrEmpty(VtblIndexValue)
53+
&& long.TryParse(
54+
VtblIndexValue,
55+
CultureInfo.InvariantCulture,
56+
out var vtblindex
57+
) ? vtblindex : null;
58+
}
59+
60+
init
61+
{
62+
VtblIndexValue = value.HasValue
63+
? value.Value.ToString(CultureInfo.InvariantCulture)
64+
: null;
65+
}
66+
}
67+
68+
[XmlElement("attribute")]
69+
public List<string> Attributes { get; } = [];
70+
71+
[XmlElement("type")]
72+
public required TypeWithNativeTypeNameElement ReturnType { get; init; }
73+
74+
[XmlElement("param")]
75+
public List<ParameterDescElement> Parameters { get; } = [];
76+
}
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 IidDescElement : NamedDescElement
9+
{
10+
[XmlAttribute("value")]
11+
public required string Value { get; init; }
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.ComponentModel;
4+
using System.Xml.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
[XmlType]
9+
public class IndexerDeclElement
10+
{
11+
[XmlAttribute("access")]
12+
public required string AccessSpecifier { get; init; }
13+
14+
[XmlAttribute("unsafe")]
15+
public bool IsUnsafe { get; init; }
16+
17+
[XmlIgnore]
18+
[EditorBrowsable(EditorBrowsableState.Never)]
19+
public bool IsUnsafeSpecified => IsUnsafe;
20+
21+
[XmlElement("type")]
22+
public required string Type { get; init; }
23+
24+
[XmlElement("param")]
25+
public required ParameterDescElement IndexerParameter { get; init; }
26+
27+
[XmlElement("get")]
28+
public required PropertyAccessorElement Getter { get; init; }
29+
}
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.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
[XmlType]
9+
public class InterfaceElement
10+
{
11+
[XmlElement("constant", typeof(ConstantDescElement))]
12+
[XmlElement("field", typeof(FieldDescElement))]
13+
[XmlElement("function", typeof(FunctionDescElement))]
14+
public List<NamedAccessDescElement> Decls { get; } = [];
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.ComponentModel;
5+
using System.Xml.Serialization;
6+
7+
namespace ClangSharp.XML;
8+
9+
[XmlType]
10+
public class MethodClassElement : NamedAccessDescElement
11+
{
12+
[XmlAttribute("static")]
13+
public bool IsStatic { get; init; }
14+
15+
[XmlIgnore]
16+
[EditorBrowsable(EditorBrowsableState.Never)]
17+
public bool IsStaticSpecified => IsStatic;
18+
19+
[XmlAttribute("unsafe")]
20+
public bool IsUnsafe { get; init; }
21+
22+
[XmlIgnore]
23+
[EditorBrowsable(EditorBrowsableState.Never)]
24+
public bool IsUnsafeSpecified => IsUnsafe;
25+
26+
[XmlElement("constant", typeof(ConstantDescElement))]
27+
[XmlElement("field", typeof(FieldDescElement))]
28+
[XmlElement("function", typeof(FunctionDescElement))]
29+
[XmlElement("delegate", typeof(DelegateDescElement))]
30+
[XmlElement("iid", typeof(IidDescElement))]
31+
public List<NamedDescElement> Decls { get; } = [];
32+
}
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+
4+
using System.Xml.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
public abstract class NamedAccessDescElement : NamedDescElement
9+
{
10+
[XmlAttribute("access")]
11+
public required string AccessSpecifier { get; init; }
12+
}
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+
4+
using System.Xml.Serialization;
5+
6+
namespace ClangSharp.XML;
7+
8+
public abstract class NamedDescElement
9+
{
10+
[XmlAttribute("name")]
11+
public required string Name { get; init; }
12+
}

0 commit comments

Comments
 (0)