Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Ical.Net.Tests/SymmetricSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static IEnumerable UriAttachment_TestCases()
yield return new TestCaseData("\\\\uncPath\\to\\resource.txt", new Uri("\\\\uncPath\\to\\resource.txt")).SetName("UNC path URL");
}

[Test, Ignore("TODO: Fix CATEGORIES multiple serializations")]
[Test]
public void CategoriesTest()
{
var vEvent = GetSimpleEvent();
Expand Down
26 changes: 23 additions & 3 deletions Ical.Net/Serialization/PropertySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,35 @@ public PropertySerializer(SerializationContext ctx) : base(ctx) { }
// the property and parameter values
var sf = GetService<ISerializerFactory>();

// TODO: Exhaust this list with all properties which can be displayed in one line.
var stringBuilder = prop.Name switch
{
"CATEGORIES" => ToOneLine(prop, sf),
_ => ToMultipleLines(prop, sf),
};

// Pop the object off the serialization context.
SerializationContext.Pop();
return stringBuilder.ToString();
}

private StringBuilder ToOneLine(ICalendarProperty prop, ISerializerFactory sf)
{
var result = new StringBuilder();
SerializeValue(result, prop, prop.Values.Where(e => e is not null), sf);

return result;
}

private StringBuilder ToMultipleLines(ICalendarProperty prop, ISerializerFactory sf)
{
var result = new StringBuilder();
foreach (var v in prop.Values.Where(value => value != null))
{
SerializeValue(result, prop, v!, sf);
}

// Pop the object off the serialization context.
SerializationContext.Pop();
return result.ToString();
return result;
}

private void SerializeValue(StringBuilder result, ICalendarProperty prop, object value, ISerializerFactory sf)
Expand Down
Loading