forked from ical-org/ical.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventSerializer.cs
35 lines (28 loc) · 891 Bytes
/
EventSerializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Copyright ical.net project maintainers and contributors.
// Licensed under the MIT license.
//
using System;
using Ical.Net.CalendarComponents;
namespace Ical.Net.Serialization;
public class EventSerializer : ComponentSerializer
{
public EventSerializer() { }
public EventSerializer(SerializationContext ctx) : base(ctx) { }
public override Type TargetType => typeof(CalendarEvent);
public override string SerializeToString(object obj)
{
var evt = obj as CalendarEvent;
CalendarEvent actualEvent;
if (evt.Properties.ContainsKey("DURATION") && evt.Properties.ContainsKey("DTEND"))
{
actualEvent = evt.Copy<CalendarEvent>();
actualEvent.Properties.Remove("DURATION");
}
else
{
actualEvent = evt;
}
return base.SerializeToString(actualEvent);
}
}