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
made Methods static
  • Loading branch information
SpocWeb committed Dec 6, 2022
commit e10b2e82b37999ebf4b7f953689f095d3da12453
110 changes: 110 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,113 @@

# Default severity for analyzer diagnostics with category 'Performance'
dotnet_analyzer_diagnostic.category-Performance.severity = warning
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = false:silent

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
[*.cs]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.private_or_internal_field_should_be_pascalcase_.severity = suggestion
dotnet_naming_rule.private_or_internal_field_should_be_pascalcase_.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_pascalcase_.style = pascalcase_

dotnet_naming_rule.private_or_internal_static_field_should_be_pascalcase_.severity = suggestion
dotnet_naming_rule.private_or_internal_static_field_should_be_pascalcase_.symbols = private_or_internal_static_field
dotnet_naming_rule.private_or_internal_static_field_should_be_pascalcase_.style = pascalcase_

dotnet_naming_rule.private_method_should_be_pascalcase_.severity = suggestion
dotnet_naming_rule.private_method_should_be_pascalcase_.symbols = private_method
dotnet_naming_rule.private_method_should_be_pascalcase_.style = pascalcase_

# Symbol specifications

dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_field.required_modifiers =

dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static

dotnet_naming_symbols.private_method.applicable_kinds = method
dotnet_naming_symbols.private_method.applicable_accessibilities = private
dotnet_naming_symbols.private_method.required_modifiers =

# Naming styles

dotnet_naming_style.pascalcase_.required_prefix =
dotnet_naming_style.pascalcase_.required_suffix = _
dotnet_naming_style.pascalcase_.word_separator =
dotnet_naming_style.pascalcase_.capitalization = pascal_case

dotnet_naming_style.pascalcase_.required_prefix =
dotnet_naming_style.pascalcase_.required_suffix = _
dotnet_naming_style.pascalcase_.word_separator =
dotnet_naming_style.pascalcase_.capitalization = pascal_case

dotnet_naming_style.pascalcase_.required_prefix =
dotnet_naming_style.pascalcase_.required_suffix = _
dotnet_naming_style.pascalcase_.word_separator =
dotnet_naming_style.pascalcase_.capitalization = pascal_case

# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = warning

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
2 changes: 1 addition & 1 deletion src/Ical.Net.CoreUnitTests/AlarmTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AlarmTest
{
private const string _tzid = "US-Eastern";

public void TestAlarm(string calendarString, List<IDateTime> dates, CalDateTime start, CalDateTime end)
public static void TestAlarm(string calendarString, List<IDateTime> dates, CalDateTime start, CalDateTime end)
{
var iCal = Calendar.Load(calendarString);
ProgramTest.TestCal(iCal);
Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net.CoreUnitTests/EqualityAndHashingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void CalDateTimeTests()
Assert.AreNotEqual(asLocal, asUtc);
}

private void TestComparison(Func<CalDateTime, IDateTime, bool> calOp, Func<int?, int?, bool> intOp)
private static void TestComparison(Func<CalDateTime, IDateTime, bool> calOp, Func<int?, int?, bool> intOp)
{
int? intSome = 1;
int? intGreater = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net.CoreUnitTests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RecurrenceTests
{
private const string _tzid = "US-Eastern";

private void EventOccurrenceTest(
private static void EventOccurrenceTest(
Calendar cal,
IDateTime fromDate,
IDateTime toDate,
Expand Down
8 changes: 4 additions & 4 deletions src/Ical.Net/CalendarComponents/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public string Summary
set => Properties.Set("SUMMARY", value);
}

public Trigger Trigger
public Trigger? Trigger
{
get => Properties.Get<Trigger>(TriggerRelation.Key);
set => Properties.Set(TriggerRelation.Key, value);
Expand Down Expand Up @@ -91,7 +91,7 @@ public IList<AlarmOccurrence> GetOccurrences(IRecurringComponent rc, IDateTime f
fromDate = rc.Start.Copy<IDateTime>();
}

var d = default(TimeSpan);
TimeSpan? d = default;
foreach (var o in rc.GetOccurrences(fromDate, toDate))
{
var dt = o.Period.StartTime;
Expand All @@ -108,12 +108,12 @@ public IList<AlarmOccurrence> GetOccurrences(IRecurringComponent rc, IDateTime f
// Use the "last-found" duration as a reference point
else if (d != default)
{
dt = o.Period.StartTime.Add(d);
dt = o.Period.StartTime.Add(d.Value);
}
else
{
throw new ArgumentException(
"Alarm trigger is relative to the START of the occurrence; however, the occurence has no discernible end.");
"Alarm trigger is relative to the START of the occurrence; however, the occurrence has no discernible end.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net/CalendarComponents/CalendarComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CalendarComponent : CalendarObject, ICalendarComponent
/// </summary>
public CalendarPropertyList Properties { get; protected set; }

public CalendarComponent() : base()
public CalendarComponent()
{
Initialize();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net/CalendarComponents/RecurringComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IList<Attachment> Attachments
set => Properties.Set("ATTACH", value);
}

/// <summary> AKA Tags; a List of <see cref="String"/> Category Names </summary>
/// <summary> AKA Tags; a List of <see cref="string"/> Category Names </summary>
public IList<string> Categories
{
get => Properties.GetMany<string>("CATEGORIES");
Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net/CalendarComponents/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public bool IsCompleted(IDateTime currDt)
// Evaluate to the previous occurrence.
_mEvaluator.EvaluateToPreviousOccurrence(Completed, currDt);

return _mEvaluator.Periods.Cast<Period>().All(p => !p.StartTime.GreaterThan(Completed) || !currDt.GreaterThanOrEqual(p.StartTime));
return _mEvaluator.Periods.All(p => !p.StartTime.GreaterThan(Completed) || !currDt.GreaterThanOrEqual(p.StartTime));
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
if (obj.GetType() != GetType()) return false;
return Equals((VTimeZone)obj);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Ical.Net/Collections/GroupedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Clear()
_lists.Clear();
}

public bool ContainsKey(TGroup group) => _dictionary.ContainsKey(@group);
public bool ContainsKey(TGroup group) => _dictionary.ContainsKey(group);

public int Count => _lists.Sum(list => list.Count);

Expand All @@ -114,8 +114,8 @@ public int CountOf(TGroup group) => _dictionary.ContainsKey(group)

public IEnumerable<TItem> Values() => _dictionary.Values.SelectMany(i => i);

public IEnumerable<TItem> AllOf(TGroup group) => _dictionary.ContainsKey(@group)
? (IEnumerable<TItem>) _dictionary[@group]
public IEnumerable<TItem> AllOf(TGroup group) => _dictionary.ContainsKey(group)
? (IEnumerable<TItem>) _dictionary[group]
: new TItem[0];

public bool Remove(TItem obj)
Expand Down
18 changes: 9 additions & 9 deletions src/Ical.Net/DataTypes/Period.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public override void CopyFrom(ICopyable obj)

protected bool Equals(Period other) => Equals(StartTime, other.StartTime) && Equals(EndTime, other.EndTime) && Duration.Equals(other.Duration);

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Period) obj);
}
Expand All @@ -85,17 +85,17 @@ public override string ToString()

private void ExtrapolateTimes()
{
if (EndTime == null && StartTime != null && Duration != default)
if (EndTime == null && StartTime != null && Duration != null)
{
EndTime = StartTime.Add(Duration);
EndTime = StartTime.Add(Duration.Value);
}
else if (Duration == default && StartTime != null && EndTime != null)
else if (Duration == null && StartTime != null && EndTime != null)
{
Duration = EndTime.Subtract(StartTime);
}
else if (StartTime == null && Duration != default && EndTime != null)
else if (StartTime == null && Duration != null && EndTime != null)
{
StartTime = EndTime.Subtract(Duration);
StartTime = EndTime.Subtract(Duration.Value);
}
}

Expand Down Expand Up @@ -131,8 +131,8 @@ public IDateTime? EndTime
}
}

private TimeSpan _duration;
public TimeSpan Duration
private TimeSpan? _duration;
public TimeSpan? Duration
{
get
{
Expand Down
29 changes: 29 additions & 0 deletions src/Ical.Net/DataTypes/RecurrencePattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@

namespace Ical.Net.DataTypes
{

public static class XRecurrence
{
public static void IncrementDate(this RecurrencePattern pattern, ref DateTime dt) => pattern.IncrementDate_(ref dt, pattern.Interval);
public static void DecrementDate(this RecurrencePattern pattern, ref DateTime dt) => pattern.IncrementDate_(ref dt, -pattern.Interval);
static void IncrementDate_(this RecurrencePattern pattern, ref DateTime dt, int interval)
{
// FIXME: use a more specific exception.
if (interval == 0)
{
throw new Exception("Cannot evaluate with an interval of zero. Please use an interval other than zero.");
}

var old = dt;
dt = pattern.Frequency switch
{
FrequencyType.Secondly => old.AddSeconds(interval),
FrequencyType.Minutely => old.AddMinutes(interval),
FrequencyType.Hourly => old.AddHours(interval),
FrequencyType.Daily => old.AddDays(interval),
FrequencyType.Weekly => old.AddWeeks(interval, pattern.FirstDayOfWeek),
FrequencyType.Monthly => old.AddDays(-old.Day + 1).AddMonths(interval),
FrequencyType.Yearly => old.AddDays(-old.DayOfYear + 1).AddYears(interval),
_ => throw new Exception(
"FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.")
};
}

}
/// <summary> An iCalendar representation of the <c>RRULE</c> property. https://tools.ietf.org/html/rfc5545#section-3.3.10 </summary>
/// <remarks>
/// Multiple Patterns are combined into a <see cref="CalendarComponents.CalendarEvent"/>
Expand Down
26 changes: 1 addition & 25 deletions src/Ical.Net/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using Ical.Net.DataTypes;
using Ical.Net.Utility;

namespace Ical.Net.Evaluation
{
Expand Down Expand Up @@ -41,36 +40,13 @@ private void Initialize()
MPeriods = new HashSet<Period>();
}

protected IDateTime ConvertToIDateTime(DateTime dt, IDateTime referenceDate)
protected static IDateTime ConvertToIDateTime(DateTime dt, IDateTime referenceDate)
{
IDateTime newDt = new CalDateTime(dt, referenceDate.TzId);
newDt.AssociateWith(referenceDate);
return newDt;
}

protected void IncrementDate(RecurrencePattern pattern, ref DateTime dt, int interval)
{
// FIXME: use a more specific exception.
if (interval == 0)
{
throw new Exception("Cannot evaluate with an interval of zero. Please use an interval other than zero.");
}

var old = dt;
dt = pattern.Frequency switch
{
FrequencyType.Secondly => old.AddSeconds(interval),
FrequencyType.Minutely => old.AddMinutes(interval),
FrequencyType.Hourly => old.AddHours(interval),
FrequencyType.Daily => old.AddDays(interval),
FrequencyType.Weekly => old.AddWeeks(interval, pattern.FirstDayOfWeek),
FrequencyType.Monthly => old.AddDays(-old.Day + 1).AddMonths(interval),
FrequencyType.Yearly => old.AddDays(-old.DayOfYear + 1).AddYears(interval),
_ => throw new Exception(
"FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.")
};
}

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

public DateTime EvaluationStartBounds
Expand Down
Loading