Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions Ical.Net/Collections/GroupedListEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class GroupedListEnumerator<TType> :
public GroupedListEnumerator(IList<IMultiLinkedList<TType>> lists) => _lists = lists;

public virtual TType Current
=> _listEnumerator == null || _listEnumerator.Current == null
? throw new InvalidOperationException("Current is null.")
=> _listEnumerator == null
? throw new InvalidOperationException("List enumerator is null.")
: _listEnumerator.Current;

public virtual void Dispose()
Expand All @@ -39,8 +39,8 @@ private void DisposeListEnumerator()
}

object IEnumerator.Current
=> _listEnumerator == null || _listEnumerator.Current == null
? throw new InvalidOperationException("Current is null.")
=> _listEnumerator == null
? throw new InvalidOperationException("List enumerator is null.")
: _listEnumerator.Current;

private bool MoveNextList()
Expand Down
7 changes: 2 additions & 5 deletions Ical.Net/Collections/Proxies/GroupedValueListProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public virtual void Add(TNewValue item)

public virtual void Clear()
{
var items = Items.Where(o => o.Values != null);

foreach (var original in items)
foreach (var original in Items)
{
// Clear all values from each matching object
original.SetValue(default(TOriginalValue)!);
Expand All @@ -108,7 +106,6 @@ public virtual void Clear()
public virtual void CopyTo(TNewValue[] array, int arrayIndex)
{
Items
.Where(o => o.Values != null)
.SelectMany(o => o.Values!)
.ToArray()
.CopyTo(array, arrayIndex);
Expand Down Expand Up @@ -153,7 +150,7 @@ public virtual int IndexOf(TNewValue item)
var value = (TOriginalValue) (object) item;
IterateValues((o, i, count) =>
{
if (o.Values != null && o.Values.Contains(value))
if (o.Values.Contains(value))
{
var list = o.Values.ToList();
index = i + list.IndexOf(value);
Expand Down
11 changes: 5 additions & 6 deletions Ical.Net/Evaluation/RecurringEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RecurringEvaluator(IRecurrable obj)
/// <param name="options"></param>
protected IEnumerable<Period> EvaluateRRule(CalDateTime referenceDate, CalDateTime? periodStart, EvaluationOptions? options)
{
if (Recurrable.RecurrenceRules == null || !Recurrable.RecurrenceRules.Any())
if (!Recurrable.RecurrenceRules.Any())
return [];

var periodsQueries = Recurrable.RecurrenceRules.Select(rule =>
Expand Down Expand Up @@ -66,7 +66,7 @@ protected IEnumerable<Period> EvaluateRDate(CalDateTime referenceDate, CalDateTi
/// <param name="options"></param>
protected IEnumerable<Period> EvaluateExRule(CalDateTime referenceDate, CalDateTime? periodStart, EvaluationOptions? options)
{
if (Recurrable.ExceptionRules == null || !Recurrable.ExceptionRules.Any())
if (!Recurrable.ExceptionRules.Any())
return [];

var exRuleEvaluatorQueries = Recurrable.ExceptionRules.Select(exRule =>
Expand Down Expand Up @@ -105,10 +105,9 @@ public override IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateT
// Only add referenceDate if there are no RecurrenceRules defined. This is in line
// with RFC 5545 which requires DTSTART to match any RRULE. If it doesn't, the behaviour
// is undefined. It seems to be good practice not to return the referenceDate in this case.
if ((Recurrable.RecurrenceRules == null) || !Recurrable.RecurrenceRules.Any())
rruleOccurrences = [new Period(referenceDate)];
else
rruleOccurrences = EvaluateRRule(referenceDate, periodStart, options);
rruleOccurrences = !Recurrable.RecurrenceRules.Any()
? [new Period(referenceDate)]
: EvaluateRRule(referenceDate, periodStart, options);

var rdateOccurrences = EvaluateRDate(referenceDate, periodStart);

Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Serialization/ComponentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ComponentSerializer(SerializationContext ctx) : base(ctx) { }

public override string? SerializeToString(object? obj)
{
if (obj is not ICalendarComponent c || SerializationContext == null)
if (obj is not ICalendarComponent c)
{
return null;
}
Expand Down
4 changes: 0 additions & 4 deletions Ical.Net/Serialization/DataMapSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public DataMapSerializer(SerializationContext ctx) : base(ctx) { }
{
var sf = GetService<ISerializerFactory>();
var mapper = GetService<DataTypeMapper>();
if (sf == null || mapper == null || SerializationContext == null)
{
return null;
}

var obj = SerializationContext.Peek();

Expand Down
5 changes: 1 addition & 4 deletions Ical.Net/Serialization/DataTypes/AttachmentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public AttachmentSerializer(SerializationContext ctx) : base(ctx) { }

// Get the currently-used encoding off the encoding stack.
var encodingStack = GetService<EncodingStack>();
if (encodingStack != null)
{
a.ValueEncoding = encodingStack.Current;
}
a.ValueEncoding = encodingStack.Current;

// Get the format of the attachment
var valueType = a.GetValueType();
Expand Down
9 changes: 3 additions & 6 deletions Ical.Net/Serialization/DataTypes/PeriodListSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PeriodListSerializer(SerializationContext ctx) : base(ctx) { }
public override string? SerializeToString(object? obj)
{
var factory = GetService<ISerializerFactory>();
if (obj is not PeriodList periodList || factory == null || SerializationContext == null)
if (obj is not PeriodList periodList)
{
return null;
}
Expand Down Expand Up @@ -69,12 +69,9 @@ public PeriodListSerializer(SerializationContext ctx) : base(ctx) { }
var value = tr.ReadToEnd();

// Create the day specifier and associate it with a calendar object
var rdt = CreateAndAssociate() as PeriodList;
if (CreateAndAssociate() is not PeriodList rdt) return null;

var factory = GetService<ISerializerFactory>();
if (rdt == null || factory == null || SerializationContext == null)
{
return null;
}

// Decode the value, if necessary
value = Decode(rdt, value);
Expand Down
8 changes: 2 additions & 6 deletions Ical.Net/Serialization/DataTypes/PeriodSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PeriodSerializer(SerializationContext ctx) : base(ctx) { }
{
var factory = GetService<ISerializerFactory>();

if (obj is not Period p || factory == null)
if (obj is not Period p)
{
return null;
}
Expand Down Expand Up @@ -78,12 +78,8 @@ public PeriodSerializer(SerializationContext ctx) : base(ctx) { }
{
var value = tr.ReadToEnd();

var p = CreateAndAssociate() as Period;
if (CreateAndAssociate() is not Period p) return null;
var factory = GetService<ISerializerFactory>();
if (p == null || factory == null)
{
return null;
}

var dtSerializer = factory.Build(typeof(CalDateTime), SerializationContext) as IStringSerializer;
var durationSerializer = factory.Build(typeof(Duration), SerializationContext) as IStringSerializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
public override string? SerializeToString(object? obj)
{
var factory = GetService<ISerializerFactory>();
if (obj is not RecurrencePattern recur || factory == null || SerializationContext == null)
if (obj is not RecurrencePattern recur)
{
return null;
}
Expand Down Expand Up @@ -205,10 +205,10 @@
System.Diagnostics.Debug.Assert(factory != null);

// Decode the value, if necessary
value = Decode(r, value);

Check warning on line 208 in Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'dt' in 'string? EncodableDataTypeSerializer.Decode(IEncodableDataType dt, string value)'.

Check warning on line 208 in Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'dt' in 'string? EncodableDataTypeSerializer.Decode(IEncodableDataType dt, string value)'.
if (value == null) return null;

DeserializePattern(value, r, factory);

Check warning on line 211 in Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'factory' in 'void RecurrencePatternSerializer.DeserializePattern(string value, RecurrencePattern r, ISerializerFactory factory)'.

Check warning on line 211 in Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'factory' in 'void RecurrencePatternSerializer.DeserializePattern(string value, RecurrencePattern r, ISerializerFactory factory)'.
return r;
}

Expand Down
11 changes: 1 addition & 10 deletions Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public RequestStatusSerializer(SerializationContext ctx) : base(ctx) { }

public override string? SerializeToString(object? obj)
{
if (SerializationContext == null)
{
return null;
}

try
{
if (obj is not RequestStatus rs)
Expand Down Expand Up @@ -73,7 +68,7 @@ public RequestStatusSerializer(SerializationContext ctx) : base(ctx) { }

public override object? Deserialize(TextReader? tr)
{
if (tr == null || SerializationContext == null) return null;
if (tr == null) return null;

var value = tr.ReadToEnd();

Expand All @@ -92,10 +87,6 @@ public RequestStatusSerializer(SerializationContext ctx) : base(ctx) { }
try
{
var factory = GetService<ISerializerFactory>();
if (factory == null)
{
return null;
}

var match = NarrowRequestMatch.Match(value);
if (!match.Success)
Expand Down
8 changes: 0 additions & 8 deletions Ical.Net/Serialization/DataTypes/TriggerSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public TriggerSerializer(SerializationContext ctx) : base(ctx) { }
try
{
var factory = GetService<ISerializerFactory>();
if (factory == null)
{
return null;
}

var valueType = t.GetValueType() ?? typeof(Duration);
if (!(factory.Build(valueType, SerializationContext) is IStringSerializer serializer))
Expand Down Expand Up @@ -88,10 +84,6 @@ public TriggerSerializer(SerializationContext ctx) : base(ctx) { }
}

var factory = GetService<ISerializerFactory>();
if (factory == null)
{
return null;
}

var valueType = t.GetValueType() ?? typeof(Duration);
var serializer = factory.Build(valueType, SerializationContext) as IStringSerializer;
Expand Down
5 changes: 0 additions & 5 deletions Ical.Net/Serialization/SerializationUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public static void OnDeserialized(object obj)
private static readonly ConcurrentDictionary<Type, List<MethodInfo>> _onDeserializingMethods = new ConcurrentDictionary<Type, List<MethodInfo>>();
private static List<MethodInfo> GetDeserializingMethods(Type targetType)
{
if (targetType == null)
{
return new List<MethodInfo>();
}

if (_onDeserializingMethods.ContainsKey(targetType))
{
return _onDeserializingMethods[targetType];
Expand Down
Loading