Skip to content
Closed
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
Prev Previous commit
Next Next commit
AutoProperties
  • Loading branch information
SpocWeb committed Dec 8, 2022
commit 218b28c0e68eed015c67b3e3cfa18a6dbfa593d3
31 changes: 12 additions & 19 deletions src/Ical.Net/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ public static IList<T> Load<T>(TextReader tr)
public static IList<T> Load<T>(string ical)
=> Load<T>(new StringReader(ical));

IUniqueComponentList<IUniqueComponent> _mUniqueComponents;
IUniqueComponentList<CalendarEvent> _mEvents;
IUniqueComponentList<Todo> _mTodos;
ICalendarObjectList<Journal> _mJournals;
IUniqueComponentList<FreeBusy> _mFreeBusy;
ICalendarObjectList<VTimeZone> _mTimeZones;

/// <summary>
/// To load an existing an iCalendar object, use one of the provided LoadFromXXX methods.
/// <example>
Expand All @@ -68,12 +61,12 @@ public Calendar()

void Initialize()
{
_mUniqueComponents = new UniqueComponentListProxy<IUniqueComponent>(Children);
_mEvents = new UniqueComponentListProxy<CalendarEvent>(Children);
_mTodos = new UniqueComponentListProxy<Todo>(Children);
_mJournals = new CalendarObjectListProxy<Journal>(Children);
_mFreeBusy = new UniqueComponentListProxy<FreeBusy>(Children);
_mTimeZones = new CalendarObjectListProxy<VTimeZone>(Children);
UniqueComponents = new UniqueComponentListProxy<IUniqueComponent>(Children);
Events = new UniqueComponentListProxy<CalendarEvent>(Children);
Todos = new UniqueComponentListProxy<Todo>(Children);
Journals = new CalendarObjectListProxy<Journal>(Children);
FreeBusy = new UniqueComponentListProxy<FreeBusy>(Children);
TimeZones = new CalendarObjectListProxy<VTimeZone>(Children);
}

protected override void OnDeserializing(StreamingContext context)
Expand Down Expand Up @@ -120,34 +113,34 @@ public override int GetHashCode()
}
}

public IUniqueComponentList<IUniqueComponent> UniqueComponents => _mUniqueComponents;
public IUniqueComponentList<IUniqueComponent> UniqueComponents { get; private set; }

public IEnumerable<IRecurrable> RecurringItems => Children.OfType<IRecurrable>();

/// <summary>
/// A collection of <see cref="Components.Event"/> components in the iCalendar.
/// </summary>
public IUniqueComponentList<CalendarEvent> Events => _mEvents;
public IUniqueComponentList<CalendarEvent> Events { get; private set; }

/// <summary>
/// A collection of <see cref="CalendarComponents.FreeBusy"/> components in the iCalendar.
/// </summary>
public IUniqueComponentList<FreeBusy> FreeBusy => _mFreeBusy;
public IUniqueComponentList<FreeBusy> FreeBusy { get; private set; }

/// <summary>
/// A collection of <see cref="Journal"/> components in the iCalendar.
/// </summary>
public ICalendarObjectList<Journal> Journals => _mJournals;
public ICalendarObjectList<Journal> Journals { get; private set; }

/// <summary>
/// A collection of VTimeZone components in the iCalendar.
/// </summary>
public ICalendarObjectList<VTimeZone> TimeZones => _mTimeZones;
public ICalendarObjectList<VTimeZone> TimeZones { get; private set; }

/// <summary>
/// A collection of <see cref="Todo"/> components in the iCalendar.
/// </summary>
public IUniqueComponentList<Todo> Todos => _mTodos;
public IUniqueComponentList<Todo> Todos { get; private set; }

public string Version
{
Expand Down
8 changes: 3 additions & 5 deletions src/Ical.Net/CalendarObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ namespace Ical.Net
{
public class CalendarObjectBase : ICopyable, ILoadable
{
bool _mIsLoaded;

public CalendarObjectBase()
{
_mIsLoaded = true;
IsLoaded = true;
}

/// <summary>
Expand All @@ -35,13 +33,13 @@ public T Copy<T>()
return default;
}

public bool IsLoaded => _mIsLoaded;
public bool IsLoaded { get; private set; }

public event EventHandler Loaded;

public void OnLoaded()
{
_mIsLoaded = true;
IsLoaded = true;
Loaded?.Invoke(this, EventArgs.Empty);
}
}
Expand Down
19 changes: 4 additions & 15 deletions src/Ical.Net/DataTypes/CalDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public sealed class CalDateTime : EncodableDataType, IDateTime

public static CalDateTime Today => new CalDateTime(DateTime.Today);

bool _hasDate;
bool _hasTime;

public CalDateTime() { }

public CalDateTime(IDateTime value)
Expand Down Expand Up @@ -144,8 +141,8 @@ public override void CopyFrom(ICopyable obj)
}

_value = dt.Value;
_hasDate = dt.HasDate;
_hasTime = dt.HasTime;
HasDate = dt.HasDate;
HasTime = dt.HasTime;

AssociateWith(dt);
}
Expand Down Expand Up @@ -288,17 +285,9 @@ public DateTime Value

public bool IsUtc => _value.Kind == DateTimeKind.Utc;

public bool HasDate
{
get => _hasDate;
set => _hasDate = value;
}
public bool HasDate { get; set; }

public bool HasTime
{
get => _hasTime;
set => _hasTime = value;
}
public bool HasTime { get; set; }

string _tzId = string.Empty;

Expand Down
32 changes: 8 additions & 24 deletions src/Ical.Net/DataTypes/RequestStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,11 @@ namespace Ical.Net.DataTypes
/// </summary>
public class RequestStatus : EncodableDataType
{
string _mDescription;
string _mExtraData;
StatusCode _mStatusCode;
public string Description { get; set; }

public string Description
{
get => _mDescription;
set => _mDescription = value;
}
public string ExtraData { get; set; }

public string ExtraData
{
get => _mExtraData;
set => _mExtraData = value;
}

public StatusCode StatusCode
{
get => _mStatusCode;
set => _mStatusCode = value;
}
public StatusCode StatusCode { get; set; }

public RequestStatus() {}

Expand Down Expand Up @@ -60,8 +44,8 @@ public override string ToString()
return serializer.SerializeToString(this);
}

protected bool Equals(RequestStatus other) => string.Equals(_mDescription, other._mDescription) && string.Equals(_mExtraData, other._mExtraData) &&
Equals(_mStatusCode, other._mStatusCode);
protected bool Equals(RequestStatus other) => string.Equals(Description, other.Description) && string.Equals(ExtraData, other.ExtraData) &&
Equals(StatusCode, other.StatusCode);

public override bool Equals(object obj)
{
Expand All @@ -84,9 +68,9 @@ public override int GetHashCode()
{
unchecked
{
var hashCode = _mDescription?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (_mExtraData?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (_mStatusCode?.GetHashCode() ?? 0);
var hashCode = Description?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (ExtraData?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (StatusCode?.GetHashCode() ?? 0);
return hashCode;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/Ical.Net/DataTypes/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class Trigger : EncodableDataType
{
IDateTime _mDateTime;
TimeSpan? _mDuration;
string _mRelated = TriggerRelation.Start;

public IDateTime DateTime
{
Expand Down Expand Up @@ -52,11 +51,7 @@ public TimeSpan? Duration
}
}

public string Related
{
get => _mRelated;
set => _mRelated = value;
}
public string Related { get; set; } = TriggerRelation.Start;

public bool IsRelative => _mDuration != null;

Expand Down Expand Up @@ -86,7 +81,7 @@ public override void CopyFrom(ICopyable obj)
Related = trigger.Related;
}

protected bool Equals(Trigger other) => Equals(_mDateTime, other._mDateTime) && _mDuration.Equals(other._mDuration) && _mRelated == other._mRelated;
protected bool Equals(Trigger other) => Equals(_mDateTime, other._mDateTime) && _mDuration.Equals(other._mDuration) && Related == other.Related;

public override bool Equals(object obj)
{
Expand All @@ -111,7 +106,7 @@ public override int GetHashCode()
{
var hashCode = _mDateTime?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ _mDuration.GetHashCode();
hashCode = (hashCode * 397) ^ _mRelated?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ Related?.GetHashCode() ?? 0;
return hashCode;
}
}
Expand Down
19 changes: 4 additions & 15 deletions src/Ical.Net/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace Ical.Net.Evaluation
{
public abstract class Evaluator : IEvaluator
{
DateTime _mEvaluationStartBounds = DateTime.MaxValue;
DateTime _mEvaluationEndBounds = DateTime.MinValue;

ICalendarObject _mAssociatedObject;
readonly ICalendarDataType _mAssociatedDataType;

Expand Down Expand Up @@ -49,17 +46,9 @@ protected static IDateTime ConvertToIDateTime(DateTime dt, IDateTime referenceDa

public System.Globalization.Calendar Calendar { get; private set; }

public DateTime EvaluationStartBounds
{
get => _mEvaluationStartBounds;
set => _mEvaluationStartBounds = value;
}
public DateTime EvaluationStartBounds { get; set; } = DateTime.MaxValue;

public DateTime EvaluationEndBounds
{
get => _mEvaluationEndBounds;
set => _mEvaluationEndBounds = value;
}
public DateTime EvaluationEndBounds { get; set; } = DateTime.MinValue;

public ICalendarObject AssociatedObject
{
Expand All @@ -71,8 +60,8 @@ public ICalendarObject AssociatedObject

public virtual void Clear()
{
_mEvaluationStartBounds = DateTime.MaxValue;
_mEvaluationEndBounds = DateTime.MinValue;
EvaluationStartBounds = DateTime.MaxValue;
EvaluationEndBounds = DateTime.MinValue;
MPeriods.Clear();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ical.Net/Evaluation/RecurringEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ public override HashSet<Period> Evaluate(IDateTime referenceDate, DateTime perio
var dateOverlaps = FindDateOverlaps(exDateExclusions);
Periods.ExceptWith(dateOverlaps);

if (EvaluationStartBounds == DateTime.MaxValue || EvaluationStartBounds > periodStart)
if (EvaluationStartBounds > periodStart)
{
EvaluationStartBounds = periodStart;
}
if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < periodEnd)
if (EvaluationEndBounds < periodEnd)
{
EvaluationEndBounds = periodEnd;
}
Expand Down
23 changes: 9 additions & 14 deletions src/Ical.Net/Evaluation/TimeZoneEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@ public class TimeZoneEvaluator : Evaluator
{
protected VTimeZone TimeZone { get; set; }

List<Occurrence> _occurrences;
public List<Occurrence> Occurrences
{
get => _occurrences;
set => _occurrences = value;
}
public List<Occurrence> Occurrences { get; set; }

public TimeZoneEvaluator(VTimeZone tz)
{
TimeZone = tz;
_occurrences = new List<Occurrence>();
Occurrences = new List<Occurrence>();
}

void ProcessOccurrences(IDateTime referenceDate)
{
// Sort the occurrences by start time
_occurrences.Sort(
Occurrences.Sort(
delegate (Occurrence o1, Occurrence o2)
{
if (o1.Period?.StartTime == null)
Expand All @@ -39,10 +34,10 @@ void ProcessOccurrences(IDateTime referenceDate)
}
);

for (var i = 0; i < _occurrences.Count; i++)
for (var i = 0; i < Occurrences.Count; i++)
{
var curr = _occurrences[i];
var next = i < _occurrences.Count - 1 ? _occurrences[i + 1] : null;
var curr = Occurrences[i];
var next = i < Occurrences.Count - 1 ? Occurrences[i + 1] : null;

// Determine end times for our periods, overwriting previously calculated end times.
// This is important because we don't want to overcalculate our time zone information,
Expand All @@ -58,7 +53,7 @@ void ProcessOccurrences(IDateTime referenceDate)
public override void Clear()
{
base.Clear();
_occurrences.Clear();
Occurrences.Clear();
}

public override HashSet<Period> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
Expand Down Expand Up @@ -109,9 +104,9 @@ public override HashSet<Period> Evaluate(IDateTime referenceDate, DateTime perio
{
Periods.Add(period);
var o = new Occurrence(curr, period);
if (!_occurrences.Contains(o))
if (!Occurrences.Contains(o))
{
_occurrences.Add(o);
Occurrences.Add(o);
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/Ical.Net/Serialization/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ namespace Ical.Net.Serialization
{
public abstract class SerializerBase : IStringSerializer
{
SerializationContext _mSerializationContext;

protected SerializerBase()
{
_mSerializationContext = SerializationContext.Default;
SerializationContext = SerializationContext.Default;
}

protected SerializerBase(SerializationContext ctx)
{
_mSerializationContext = ctx;
SerializationContext = ctx;
}

public SerializationContext SerializationContext
{
get => _mSerializationContext;
set => _mSerializationContext = value;
}
public SerializationContext SerializationContext { get; set; }

public abstract Type TargetType { get; }
public abstract string SerializeToString(object obj);
Expand Down