Skip to content

Commit 75e27ac

Browse files
authored
Merge pull request #832 from FyiurAmron/add_missing_methods_and_reorder
Add missing methods to (de)serializer interfaces and implementations +semver:fix
2 parents 3fdeb30 + ad31779 commit 75e27ac

4 files changed

Lines changed: 50 additions & 23 deletions

File tree

YamlDotNet/Serialization/Deserializer.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,26 @@ public T Deserialize<T>(TextReader input)
7777
return Deserialize<T>(new Parser(input));
7878
}
7979

80+
public T Deserialize<T>(IParser parser)
81+
{
82+
return (T)Deserialize(parser, typeof(T))!; // We really want an exception if we are trying to deserialize null into a non-nullable type
83+
}
84+
85+
public object? Deserialize(string input)
86+
{
87+
return Deserialize(input, typeof(object));
88+
}
89+
8090
public object? Deserialize(TextReader input)
8191
{
8292
return Deserialize(input, typeof(object));
8393
}
8494

95+
public object? Deserialize(IParser parser)
96+
{
97+
return Deserialize(parser, typeof(object));
98+
}
99+
85100
public object? Deserialize(string input, Type type)
86101
{
87102
using var reader = new StringReader(input);
@@ -93,16 +108,6 @@ public T Deserialize<T>(TextReader input)
93108
return Deserialize(new Parser(input), type);
94109
}
95110

96-
public T Deserialize<T>(IParser parser)
97-
{
98-
return (T)Deserialize(parser, typeof(T))!; // We really want an exception if we are trying to deserialize null into a non-nullable type
99-
}
100-
101-
public object? Deserialize(IParser parser)
102-
{
103-
return Deserialize(parser, typeof(object));
104-
}
105-
106111
/// <summary>
107112
/// Deserializes an object of the specified type.
108113
/// </summary>

YamlDotNet/Serialization/IDeserializer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ public interface IDeserializer
2929
{
3030
T Deserialize<T>(string input);
3131
T Deserialize<T>(TextReader input);
32-
object? Deserialize(TextReader input);
33-
object? Deserialize(string input, Type type);
34-
object? Deserialize(TextReader input, Type type);
3532
T Deserialize<T>(IParser parser);
33+
34+
object? Deserialize(string input);
35+
object? Deserialize(TextReader input);
3636
object? Deserialize(IParser parser);
3737

38+
object? Deserialize(string input, Type type);
39+
object? Deserialize(TextReader input, Type type);
40+
3841
/// <summary>
3942
/// Deserializes an object of the specified type.
4043
/// </summary>

YamlDotNet/Serialization/ISerializer.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@ namespace YamlDotNet.Serialization
2828
public interface ISerializer
2929
{
3030
/// <summary>
31-
/// Serializes the specified object.
31+
/// Serializes the specified object into a string.
3232
/// </summary>
33-
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
3433
/// <param name="graph">The object to serialize.</param>
35-
void Serialize(TextWriter writer, object? graph);
34+
string Serialize(object? graph);
3635

3736
/// <summary>
3837
/// Serializes the specified object into a string.
3938
/// </summary>
4039
/// <param name="graph">The object to serialize.</param>
41-
string Serialize(object? graph);
40+
/// <param name="type">The static type of the object to serialize.</param>
41+
string Serialize(object? graph, Type type);
42+
43+
/// <summary>
44+
/// Serializes the specified object.
45+
/// </summary>
46+
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
47+
/// <param name="graph">The object to serialize.</param>
48+
void Serialize(TextWriter writer, object? graph);
4249

4350
/// <summary>
4451
/// Serializes the specified object.

YamlDotNet/Serialization/Serializer.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,37 @@ public static Serializer FromValueSerializer(IValueSerializer valueSerializer, E
6363
}
6464

6565
/// <summary>
66-
/// Serializes the specified object.
66+
/// Serializes the specified object into a string.
6767
/// </summary>
68-
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
6968
/// <param name="graph">The object to serialize.</param>
70-
public void Serialize(TextWriter writer, object? graph)
69+
public string Serialize(object? graph)
7170
{
72-
Serialize(new Emitter(writer, emitterSettings), graph);
71+
using var buffer = new StringWriter();
72+
Serialize(buffer, graph);
73+
return buffer.ToString();
7374
}
7475

7576
/// <summary>
7677
/// Serializes the specified object into a string.
7778
/// </summary>
7879
/// <param name="graph">The object to serialize.</param>
79-
public string Serialize(object? graph)
80+
/// <param name="type">The static type of the object to serialize.</param>
81+
public string Serialize(object? graph, Type type)
8082
{
8183
using var buffer = new StringWriter();
82-
Serialize(buffer, graph);
84+
Serialize(buffer, graph, type);
8385
return buffer.ToString();
8486
}
87+
88+
/// <summary>
89+
/// Serializes the specified object.
90+
/// </summary>
91+
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
92+
/// <param name="graph">The object to serialize.</param>
93+
public void Serialize(TextWriter writer, object? graph)
94+
{
95+
Serialize(new Emitter(writer, emitterSettings), graph);
96+
}
8597

8698
/// <summary>
8799
/// Serializes the specified object.

0 commit comments

Comments
 (0)