Skip to content

Commit

Permalink
ref - Refactored calendar component nesting
Browse files Browse the repository at this point in the history
---

Type: ref
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 1, 2024
1 parent 86a3e7a commit a1d6ac7
Showing 1 changed file with 17 additions and 168 deletions.
185 changes: 17 additions & 168 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,12 @@ private void SaveLastSubPart(Parts.Calendar? subpart, ref Parts.Calendar part)
{
if (subpart is null)
return;
bool nestable = true;
switch (part.GetType().Name)
{
case nameof(Parts.Calendar):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside calendar");
case nameof(CalendarEvent):
part.events.Add((CalendarEvent)subpart);
break;
Expand All @@ -424,203 +423,53 @@ private void SaveLastSubPart(Parts.Calendar? subpart, ref Parts.Calendar part)
case nameof(CalendarTimeZone):
part.timeZones.Add((CalendarTimeZone)subpart);
break;
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside calendar");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside calendar");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm inside calendar");
default:
nestable = false;
break;
}
break;
case nameof(CalendarEvent):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside event");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside event");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside event");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside event");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside event");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside event");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside event");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside event");
case nameof(CalendarAlarm):
((CalendarEvent)part).alarms.Add((CalendarAlarm)subpart);
break;
default:
nestable = false;
break;
}
break;
case nameof(CalendarTodo):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside to-do");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside to-do");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside to-do");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside to-do");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside to-do");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside to-do");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside to-do");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside to-do");
case nameof(CalendarAlarm):
((CalendarTodo)part).alarms.Add((CalendarAlarm)subpart);
break;
}
break;
case nameof(CalendarJournal):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside journal");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside journal");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside journal");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside journal");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside journal");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside journal");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside journal");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside journal");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside journal");
}
break;
case nameof(CalendarFreeBusy):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside free/busy info");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside free/busy info");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside free/busy info");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside free/busy info");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside free/busy info");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside free/busy info");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside free/busy info");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside free/busy info");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside free/busy info");
default:
nestable = false;
break;
}
break;
case nameof(CalendarTimeZone):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside time zone");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside time zone");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside time zone");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside time zone");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside time zone");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside time zone");
case nameof(CalendarStandard):
((CalendarTimeZone)part).standards.Add((CalendarStandard)subpart);
break;
case nameof(CalendarDaylight):
((CalendarTimeZone)part).daylights.Add((CalendarDaylight)subpart);
break;
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside time zone");
}
break;
case nameof(CalendarStandard):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside standard time info");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside standard time info");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside standard time info");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside standard time info");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside standard time info");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside standard time info");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside standard time info");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside standard time info");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside standard time info");
}
break;
case nameof(CalendarDaylight):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside daylight time info");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside daylight time info");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside daylight time info");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside daylight time info");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside daylight time info");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside daylight time info");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside daylight time info");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside daylight time info");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside daylight time info");
default:
nestable = false;
break;
}
break;
case nameof(CalendarAlarm):
switch (subpart.GetType().Name)
{
case nameof(Parts.Calendar):
throw new ArgumentException("Can't nest calendar inside alarm info");
case nameof(CalendarEvent):
throw new ArgumentException("Can't nest event inside alarm info");
case nameof(CalendarTodo):
throw new ArgumentException("Can't nest to-do inside alarm info");
case nameof(CalendarJournal):
throw new ArgumentException("Can't nest journal inside alarm info");
case nameof(CalendarFreeBusy):
throw new ArgumentException("Can't nest free/busy inside alarm info");
case nameof(CalendarTimeZone):
throw new ArgumentException("Can't nest time zone info inside alarm info");
case nameof(CalendarStandard):
throw new ArgumentException("Can't nest standard time info inside alarm info");
case nameof(CalendarDaylight):
throw new ArgumentException("Can't nest daylight time info inside alarm info");
case nameof(CalendarAlarm):
throw new ArgumentException("Can't nest alarm info inside alarm info");
}
default:
nestable = false;
break;
}
if (!nestable)
throw new ArgumentException($"Can't place {subpart.GetType().Name} inside {part.GetType().Name}");
}

internal VCalendarParser(string[] calendarContent, Version calendarVersion)
Expand Down

0 comments on commit a1d6ac7

Please sign in to comment.