Files
runner/src/Sdk/DTObjectTemplating/ObjectTemplating/Schema/PropertyValue.cs
T

41 lines
1.5 KiB
C#
Raw Normal View History

2019-10-10 00:52:42 -04:00
using System;
2020-03-14 17:54:58 -04:00
using GitHub.DistributedTask.ObjectTemplating.Tokens;
2019-10-10 00:52:42 -04:00
namespace GitHub.DistributedTask.ObjectTemplating.Schema
{
internal sealed class PropertyValue
{
2020-03-14 17:54:58 -04:00
internal PropertyValue(TemplateToken token)
2019-10-10 00:52:42 -04:00
{
2020-03-14 17:54:58 -04:00
if (token is StringToken stringToken)
{
Type = stringToken.Value;
}
else
{
var mapping = token.AssertMapping($"{TemplateConstants.MappingPropertyValue}");
foreach (var mappingPair in mapping)
{
var mappingKey = mappingPair.Key.AssertString($"{TemplateConstants.MappingPropertyValue} key");
switch (mappingKey.Value)
{
case TemplateConstants.Type:
Type = mappingPair.Value.AssertString($"{TemplateConstants.MappingPropertyValue} {TemplateConstants.Type}").Value;
break;
case TemplateConstants.Required:
Required = mappingPair.Value.AssertBoolean($"{TemplateConstants.MappingPropertyValue} {TemplateConstants.Required}").Value;
break;
default:
mappingKey.AssertUnexpectedValue($"{TemplateConstants.MappingPropertyValue} key");
break;
}
}
}
2019-10-10 00:52:42 -04:00
}
internal String Type { get; set; }
2020-03-14 17:54:58 -04:00
internal Boolean Required { get; set; }
2019-10-10 00:52:42 -04:00
}
}