Skip to content

Commit

Permalink
creating toString for json configuration source
Browse files Browse the repository at this point in the history
  • Loading branch information
chojomok committed Nov 18, 2024
1 parent 707de2c commit c4c3f69
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class JsonConfigurationSource : IConfigurationSource, ITelemeteredConfigu
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(JsonConfigurationSource));
private readonly JToken? _configuration;
private readonly ConfigurationOrigins _origin;
private string? _configurationSource;

/// <summary>
/// Initializes a new instance of the <see cref="JsonConfigurationSource"/>
Expand All @@ -47,6 +48,12 @@ internal JsonConfigurationSource(string json, ConfigurationOrigins origin)
{
}

internal JsonConfigurationSource(string json, ConfigurationOrigins origin, string filename)
: this(json, origin, j => (JToken?)JsonConvert.DeserializeObject(j))
{
_configurationSource = filename;
}

private protected JsonConfigurationSource(string json, ConfigurationOrigins origin, Func<string, JToken?> deserialize)
{
if (json is null) { ThrowHelper.ThrowArgumentNullException(nameof(json)); }
Expand Down Expand Up @@ -75,7 +82,18 @@ public static JsonConfigurationSource FromFile(string filename)
internal static JsonConfigurationSource FromFile(string filename, ConfigurationOrigins origin)
{
var json = File.ReadAllText(filename);
return new JsonConfigurationSource(json, origin);
return new JsonConfigurationSource(json, origin, filename);
}

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>
/// A string that indicates the source of the datadog.json configuration.
/// </returns>
public override string ToString()
{
return "The datadog.json configuration is coming from " + _configurationSource;
}

/// <summary>
Expand Down

0 comments on commit c4c3f69

Please sign in to comment.