Skip to content

Commit

Permalink
Merge pull request #281 from rianjs/AddRangeExtensions
Browse files Browse the repository at this point in the history
PeriodList now implements IList<IPeriod> #280
  • Loading branch information
rianjs authored May 2, 2017
2 parents 895eeff + 7ba8fa0 commit 0883dd1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 55 deletions.
47 changes: 12 additions & 35 deletions net-core/Ical.Net/Ical.Net/DataTypes/PeriodList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,7 @@ public override void CopyFrom(ICopyable obj)

public override string ToString() => new PeriodListSerializer().SerializeToString(this);

public virtual void Add(IDateTime dt) => Periods.Add(new Period(dt));

public Period this[int index]
{
get { return Periods[index]; }
set { Periods[index] = value; }
}

public virtual void Add(Period item) => Periods.Add(item);

public IEnumerator<Period> GetEnumerator() => Periods.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => Periods.GetEnumerator();
public void Add(IDateTime dt) => Periods.Add(new Period(dt));

public static Dictionary<string, List<Period>> GetGroupedPeriods(IList<PeriodList> periodLists)
{
Expand Down Expand Up @@ -118,32 +106,21 @@ public override int GetHashCode()
}
}

public void Clear()
{
Periods.Clear();
}

public bool Contains(Period item) => Periods.Contains(item);

public void CopyTo(Period[] array, int arrayIndex)
public Period this[int index]
{
Periods.CopyTo(array, arrayIndex);
get => Periods[index];
set => Periods[index] = value;
}

public bool Remove(Period item) => Periods.Remove(item);

public bool IsReadOnly => Periods.IsReadOnly;

public int IndexOf(Period item) => Periods.IndexOf(item);

public void Insert(int index, Period item)
{
Periods.Insert(index, item);
}

public void RemoveAt(int index)
{
Periods.RemoveAt(index);
}
public void Insert(int index, Period item) => Periods.Insert(index, item);
public void RemoveAt(int index) => Periods.RemoveAt(index);
public void Add(Period item) => Periods.Add(item);
public void Clear() => Periods.Clear();
public bool Contains(Period item) => Periods.Contains(item);
public void CopyTo(Period[] array, int arrayIndex) => Periods.CopyTo(array, arrayIndex);
public IEnumerator<Period> GetEnumerator() => Periods.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => Periods.GetEnumerator();
}
}
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A listing of what each [Nuget package](https://www.nuget.org/packages/Ical.Net)

### v2

* 2.3.0: PeriodList now implements `IList` [#280](https://github.com/rianjs/ical.net/issues/280)
* 2.2.39: Bugfix: Better CalDateTime equality and hashing, because time zones matter. [#275](https://github.com/rianjs/ical.net/issues/275)
* 2.2.38: Bugfix: Fixed a small ordering bug when evaluating `EXDATE`s and `RDATE`s [#275](https://github.com/rianjs/ical.net/issues/275)
* 2.2.37: Bugfix: `Event`'s `Equals()` and `GetHashCode()` were buggy in that they did not consider `RecurrenceDates` and `ExceptionDates` properly. Both methods treated these properties as if they were a single collection. Now they are normalized by time zone when before determining whether complete set of `RDATE`s or `EXDATE`s are the same. [#275](https://github.com/rianjs/ical.net/issues/275)
Expand Down
2 changes: 1 addition & 1 deletion v2/Ical.Net.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Ical.Net</id>
<version>2.2.39</version>
<version>2.3.0</version>
<title>Ical.Net</title>
<authors>Rian Stockbower, Douglas Day, M. David Peterson</authors>
<owners>Rian Stockbower</owners>
Expand Down
37 changes: 22 additions & 15 deletions v2/ical.NET/DataTypes/PeriodList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace Ical.Net.DataTypes
/// <summary>
/// An iCalendar list of recurring dates (or date exclusions)
/// </summary>
public class PeriodList : EncodableDataType, IPeriodList
public class PeriodList : EncodableDataType, IPeriodList, IList<IPeriod>
{
public string TzId { get; set; }

public int Count => Periods.Count;
public bool IsReadOnly => Periods.IsReadOnly;

protected IList<IPeriod> Periods { get; set; } = new List<IPeriod>();

Expand Down Expand Up @@ -49,19 +51,7 @@ public override void CopyFrom(ICopyable obj)

public override string ToString() => new PeriodListSerializer().SerializeToString(this);

public virtual void Add(IDateTime dt) => Periods.Add(new Period(dt));

public IPeriod this[int index]
{
get { return Periods[index]; }
set { Periods[index] = value; }
}

public virtual void Add(IPeriod item) => Periods.Add(item);

public IEnumerator<IPeriod> GetEnumerator() => Periods.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => Periods.GetEnumerator();
public void Add(IDateTime dt) => Periods.Add(new Period(dt));

public static Dictionary<string, List<Period>> GetGroupedPeriods(IList<IPeriodList> periodLists)
{
Expand Down Expand Up @@ -98,7 +88,7 @@ public static Dictionary<string, List<Period>> GetGroupedPeriods(IList<IPeriodLi
protected bool Equals(PeriodList other)
{
return string.Equals(TzId, other.TzId, StringComparison.OrdinalIgnoreCase)
&& CollectionHelpers.Equals(Periods, other.Periods);
&& CollectionHelpers.Equals(Periods, other.Periods);
}

public override bool Equals(object obj)
Expand All @@ -117,5 +107,22 @@ public override int GetHashCode()
return hashCode;
}
}

public IPeriod this[int index]
{
get => Periods[index];
set => Periods[index] = value;
}

public bool Remove(IPeriod item) => Periods.Remove(item);
public int IndexOf(IPeriod item) => Periods.IndexOf(item);
public void Insert(int index, IPeriod item) => Periods.Insert(index, item);
public void RemoveAt(int index) => Periods.RemoveAt(index);
public void Add(IPeriod item) => Periods.Add(item);
public void Clear() => Periods.Clear();
public bool Contains(IPeriod item) => Periods.Contains(item);
public void CopyTo(IPeriod[] array, int arrayIndex) => Periods.CopyTo(array, arrayIndex);
public IEnumerator<IPeriod> GetEnumerator() => Periods.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => Periods.GetEnumerator();
}
}
5 changes: 1 addition & 4 deletions v2/ical.NET/Interfaces/DataTypes/IPeriodList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

namespace Ical.Net.Interfaces.DataTypes
{
public interface IPeriodList : IEncodableDataType, IEnumerable<IPeriod>
public interface IPeriodList : IEncodableDataType, IList<IPeriod>
{
string TzId { get; }
IPeriod this[int index] { get; }
void Add(IDateTime dt);
void Add(IPeriod item);
int Count { get; }
}
}

0 comments on commit 0883dd1

Please sign in to comment.