using System;
using GitHub.Actions.WorkflowParser.Conversion;
using GitHub.Actions.WorkflowParser.ObjectTemplating;
namespace GitHub.Actions.WorkflowParser
{
///
/// Extension methods for
///
internal static class TemplateContextExtensions
{
///
/// Stores the in the state.
///
public static void SetFeatures(
this TemplateContext context,
WorkflowFeatures features)
{
context.State[s_featuresKey] = features;
}
///
/// Gets the from the state.
///
public static WorkflowFeatures GetFeatures(this TemplateContext context)
{
if (context.State.TryGetValue(s_featuresKey, out var value) &&
value is WorkflowFeatures features)
{
return features;
}
throw new ArgumentNullException(nameof(WorkflowFeatures));
}
///
/// Stores the in the state.
///
public static void SetJobCountValidator(
this TemplateContext context,
JobCountValidator validator)
{
context.State[s_jobCountValidatorKey] = validator;
}
///
/// Gets the from the state.
///
public static JobCountValidator GetJobCountValidator(this TemplateContext context)
{
if (context.State.TryGetValue(s_jobCountValidatorKey, out var value) &&
value is JobCountValidator validator)
{
return validator;
}
throw new ArgumentNullException(nameof(JobCountValidator));
}
///
/// Lookup key for the object within the state dictionary.
///
private static readonly string s_featuresKey = typeof(WorkflowFeatures).FullName!;
///
/// Lookup key for the object within the state dictionary.
///
private static readonly string s_jobCountValidatorKey = typeof(JobCountValidator).FullName!;
}
}