in src/Core/Compiling/Policy/ValidateContentCompiler.cs [141:194]
private static void HandleContents(ICompilationContext context, InitializerValue contentTypesValue,
XElement parentElement)
{
foreach (var contentTypeValue in contentTypesValue.UnnamedValues ?? [])
{
if (!contentTypeValue.TryGetValues<ValidateContent>(out var validateContentTypeValues))
{
context.Report(Diagnostic.Create(
CompilationErrors.PolicyArgumentIsNotOfRequiredType,
contentTypeValue.Node.GetLocation(),
"validate-content.content",
nameof(ValidateContent)
));
continue;
}
XElement contentTypeElement = new("content");
if (!contentTypeElement.AddAttribute(validateContentTypeValues, nameof(ValidateContent.ValidateAs),
"validate-as"))
{
context.Report(Diagnostic.Create(
CompilationErrors.RequiredParameterNotDefined,
contentTypeValue.Node.GetLocation(),
"validate-content.content",
nameof(ValidateContent.ValidateAs)
));
continue;
}
if (!contentTypeElement.AddAttribute(validateContentTypeValues, nameof(ValidateContent.Action),
"action"))
{
context.Report(Diagnostic.Create(
CompilationErrors.RequiredParameterNotDefined,
contentTypeValue.Node.GetLocation(),
"validate-content.content",
nameof(ValidateContent.Action)
));
continue;
}
contentTypeElement.AddAttribute(validateContentTypeValues, nameof(ValidateContent.Type), "type");
contentTypeElement.AddAttribute(validateContentTypeValues, nameof(ValidateContent.SchemaId),
"schema-id");
contentTypeElement.AddAttribute(validateContentTypeValues, nameof(ValidateContent.SchemaRef),
"schema-ref");
contentTypeElement.AddAttribute(validateContentTypeValues,
nameof(ValidateContent.AllowAdditionalProperties), "allow-additional-properties");
contentTypeElement.AddAttribute(validateContentTypeValues,
nameof(ValidateContent.CaseInsensitivePropertyNames), "case-insensitive-property-names");
parentElement.Add(contentTypeElement);
}
}