-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAsyncApiStringReader.cs
More file actions
49 lines (44 loc) · 1.67 KB
/
Copy pathAsyncApiStringReader.cs
File metadata and controls
49 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Readers
{
using System.IO;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.Interface;
/// <summary>
/// Service class for converting strings into AsyncApiDocument instances.
/// </summary>
public class AsyncApiStringReader : IAsyncApiReader<string, AsyncApiDiagnostic>
{
private readonly AsyncApiReaderSettings settings;
/// <summary>
/// Constructor tha allows reader to use non-default settings.
/// </summary>
/// <param name="settings"></param>
public AsyncApiStringReader(AsyncApiReaderSettings settings = null)
{
this.settings = settings ?? new AsyncApiReaderSettings();
}
/// <summary>
/// Reads the string input and parses it into an AsyncApi document.
/// </summary>
public AsyncApiDocument Read(string input, out AsyncApiDiagnostic diagnostic)
{
using (var reader = new StringReader(input))
{
return new AsyncApiTextReader(this.settings).Read(reader, out diagnostic);
}
}
/// <summary>
/// Reads the string input and parses it into an AsyncApi element.
/// </summary>
public T ReadFragment<T>(string input, AsyncApiVersion version, out AsyncApiDiagnostic diagnostic)
where T : IAsyncApiElement
{
using (var reader = new StringReader(input))
{
return new AsyncApiTextReader(this.settings).ReadFragment<T>(reader, version, out diagnostic);
}
}
}
}