GPAL - Generally Positive Automation Library
v1.0
GPAL The Fluent Automation LIbrary
Toggle main menu visibility
Loading...
Searching...
No Matches
VersionYamlConverter.cs
1
// =============================================================================
2
// GPAL - Generally Positive Automation Library
3
// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4
//
5
// This file is part of GPAL.
6
// Licensed under the Business Source License 1.1
7
//
8
// Primary development, architecture, and vision by Michael B. Vederman,
9
// CEO of Software Decisions, Inc., Texas.
10
//
11
// Internal development maintained privately.
12
// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13
//
14
// See LICENSE for full terms, including Additional Use Grant.
15
// =============================================================================
16
17
using
System;
18
using
YamlDotNet.Core;
19
using
YamlDotNet.Core.Events;
20
using
YamlDotNet.Serialization;
21
27
public
class
VersionYamlConverter
: IYamlTypeConverter
28
{
29
public
bool
Accepts(Type type)
30
{
31
return
type == typeof(System.Version);
32
}
33
34
public
object
ReadYaml(IParser parser, Type type)
35
{
36
var scalar = parser.Consume<Scalar>();
37
38
if
(
string
.IsNullOrEmpty(scalar.Value) || scalar.Value.ToLower() ==
"null"
)
39
return
null
;
40
41
return
System.Version.Parse(scalar.Value);
42
}
43
44
public
object
ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
45
{
46
var scalarValue = rootDeserializer(typeof(
string
)) as string;
47
48
if
(
string
.IsNullOrEmpty(scalarValue) || scalarValue.ToLower() ==
"null"
)
49
return
null
;
50
51
return
System.Version.Parse(scalarValue);
52
}
53
54
public
void
WriteYaml(IEmitter emitter,
object
value, Type type)
55
{
56
if
(value ==
null
)
57
emitter.Emit(
new
Scalar(
"null"
));
58
else
59
emitter.Emit(
new
Scalar(
null
,
null
, ((System.Version)value).ToString()));
60
}
61
62
public
void
WriteYaml(IEmitter emitter,
object
value, Type type, ObjectSerializer serializer)
63
{
64
if
(value ==
null
)
65
emitter.Emit(
new
Scalar(
"null"
));
66
else
67
serializer(((System.Version)value).ToString(), typeof(
string
));
68
}
69
}
VersionYamlConverter
Writes a Version as the string everyone recognizes, "1.2.3.4", and a null as a null....
Definition
VersionYamlConverter.cs:28
Common
VersionYamlConverter.cs
Generated by
1.17.0