/
StreamConfigurationProvider.cs
57 lines (48 loc) · 1.62 KB
/
StreamConfigurationProvider.cs
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
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
namespace Microsoft.Extensions.Configuration
{
/// <summary>
/// Stream based configuration provider
/// </summary>
public abstract class StreamConfigurationProvider : ConfigurationProvider
{
/// <summary>
/// The source settings for this provider.
/// </summary>
public StreamConfigurationSource Source { get; }
private bool _loaded;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="source">The source.</param>
public StreamConfigurationProvider(StreamConfigurationSource source)
{
ThrowHelper.ThrowIfNull(source);
Source = source;
}
/// <summary>
/// Load the configuration data from the stream.
/// </summary>
/// <param name="stream">The data stream.</param>
public abstract void Load(Stream stream);
/// <summary>
/// Load the configuration data from the stream. Will throw after the first call.
/// </summary>
public override void Load()
{
if (_loaded)
{
throw new InvalidOperationException(SR.StreamConfigurationProvidersAlreadyLoaded);
}
if (Source.Stream == null)
{
throw new InvalidOperationException(SR.StreamConfigurationSourceStreamCannotBeNull);
}
Load(Source.Stream);
_loaded = true;
}
}
}