protected override void WriteAttributeTo(string pageVirtualPath, TextWriter writer, string name, PositionTagged<string> prefix, PositionTagged<string> suffix, params AttributeValue[] values)
{
bool first = true;
bool wroteSomething = false;
if (values.Length == 0)
{
// Explicitly empty attribute, so write the prefix and suffix
WritePositionTaggedLiteral(writer, pageVirtualPath, prefix);
WritePositionTaggedLiteral(writer, pageVirtualPath, suffix);
}
else
{
for (int i = 0; i < values.Length; i++)
{
AttributeValue attrVal = values[i];
PositionTagged<object> val = attrVal.Value;
PositionTagged<string> next = i == values.Length - 1 ?
suffix : // End of the list, grab the suffix
values[i + 1].Prefix; // Still in the list, grab the next prefix
bool? boolVal = null;
if (val.Value is bool)
{
boolVal = (bool)val.Value;
}
if (val.Value != null && (boolVal == null || boolVal.Value))
{
string valStr = val.Value as string;
// This shouldn't be needed any more
//if (valStr == null)
//{
// valStr = val.Value.ToString();
//}
if (boolVal != null)
{
valStr = name;
}
if (first)
{
WritePositionTaggedLiteral(writer, pageVirtualPath, prefix);
first = false;
}
else
{
WritePositionTaggedLiteral(writer, pageVirtualPath, attrVal.Prefix);
}
// Calculate length of the source span by the position of the next value (or suffix)
int sourceLength = next.Position - attrVal.Value.Position;
BeginContext(writer, pageVirtualPath, attrVal.Value.Position, sourceLength, isLiteral: attrVal.Literal);
if (attrVal.Literal)
{
WriteLiteralTo(writer, val.Value);
}
else
{
// Patch: Don't use valStr, use val.Value
WriteTo(writer, val.Value); // Write value
}
EndContext(writer, pageVirtualPath, attrVal.Value.Position, sourceLength, isLiteral: attrVal.Literal);
wroteSomething = true;
}
}
if (wroteSomething)
{
WritePositionTaggedLiteral(writer, pageVirtualPath, suffix);
}
}
}