Skip to content

Commit ca72b22

Browse files
committed
Make some structs to classes, Make all JsonConverters internal
1 parent 37c7304 commit ca72b22

6 files changed

Lines changed: 11 additions & 26 deletions

File tree

API.Test/TimeTableTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void GetTimeGrid()
3232

3333
Task<Timegrid> timegrid = Client.GetTimegridAsync();
3434
timegrid.Wait();
35-
if (timegrid.Result.SchoolDays > 0)
35+
if (timegrid.Result.SchoolDayCount > 0)
3636
Assert.Pass();
3737
else
3838
Assert.Fail();

WebUntisAPI.Client/Converter/ClassJsonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace WebUntisAPI.Client.Converter
1414
/// <summary>
1515
/// Convert the teachers in webuntis get classes response to int array
1616
/// </summary>
17-
public sealed class ClassJsonConverter : JsonConverter<Class>
17+
internal class ClassJsonConverter : JsonConverter<Class>
1818
{
1919
/// <inheritdoc/>
2020
public override Class ReadJson(JsonReader reader, Type objectType, Class existingValue, bool hasExistingValue, JsonSerializer serializer)

WebUntisAPI.Client/Converter/ColorJsonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace WebUntisAPI.Client.Converter
1414
/// <summary>
1515
/// A json converter to convert a <see cref="Color"/> to the Hex color format (RRGGBB)
1616
/// </summary>
17-
public sealed class ColorJsonConverter : JsonConverter<Color>
17+
internal class ColorJsonConverter : JsonConverter<Color>
1818
{
1919
/// <inheritdoc/>
2020
public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer)

WebUntisAPI.Client/Converter/TimegridJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace WebUntisAPI.Client.Converter
1212
{
13-
internal sealed class TimegridJsonConverter : JsonConverter<Timegrid>
13+
internal class TimegridJsonConverter : JsonConverter<Timegrid>
1414
{
1515
/// <inheritdoc/>
1616
public override Timegrid ReadJson(JsonReader reader, Type objectType, Timegrid existingValue, bool hasExistingValue, JsonSerializer serializer)
@@ -24,7 +24,7 @@ public override Timegrid ReadJson(JsonReader reader, Type objectType, Timegrid e
2424
foreach (JObject hour in dayTimegrid["timeUnits"].Cast<JObject>())
2525
hours.Add(serializer.Deserialize<SchoolHour>(hour.CreateReader()));
2626

27-
timegrid[(Day)dayTimegrid["day"].Value<int>()] = hours.ToArray();
27+
timegrid.SchoolDays.Add((Day)dayTimegrid["day"].Value<int>(), hours.ToArray());
2828
}
2929
return timegrid;
3030
}

WebUntisAPI.Client/Models/Holidays.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace WebUntisAPI.Client.Models
1313
/// A holiday
1414
/// </summary>
1515
[DebuggerDisplay("Name: {LongName, nq}")]
16-
public struct Holidays
16+
public class Holidays
1717
{
1818
/// <summary>
1919
/// The id of the holiday

WebUntisAPI.Client/Models/Timegrid.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,19 @@ namespace WebUntisAPI.Client.Models
1717
[JsonConverter(typeof(TimegridJsonConverter))]
1818
public class Timegrid : IEnumerable<(Day, SchoolHour[])>
1919
{
20-
private readonly Dictionary<Day, SchoolHour[]> _schoolDays = new Dictionary<Day, SchoolHour[]>();
21-
2220
/// <summary>
23-
/// The count of school hours (mostly 5)
21+
/// All the school days with their school hours
2422
/// </summary>
25-
public int SchoolDays => _schoolDays.Count;
23+
public Dictionary<Day, SchoolHour[]> SchoolDays { get; set; } = new Dictionary<Day, SchoolHour[]>();
2624

2725
/// <summary>
28-
/// Get the school hours by the day
26+
/// The count of school days (mostly 5)
2927
/// </summary>
30-
/// <param name="day">The day</param>
31-
/// <returns>The school hours</returns>
32-
/// <exception cref="KeyNotFoundException">Thrown when the given day not found (mostly <see cref="Day.Saturday"/> and <see cref="Day.Sunday"/>)</exception>
33-
public SchoolHour[] this[Day day]
34-
{
35-
get => _schoolDays[day];
36-
set
37-
{
38-
if (_schoolDays.ContainsKey(day))
39-
_schoolDays[day] = value;
40-
else
41-
_schoolDays.Add(day, value);
42-
}
43-
}
28+
public int SchoolDayCount => SchoolDays.Count;
4429

4530
#region IEnumerable<SchoolHour[]>
4631
/// <inheritdoc/>
47-
public IEnumerator<(Day, SchoolHour[])> GetEnumerator() => _schoolDays.Keys.Zip(_schoolDays.Values, (day, schoolHours) => (day, schoolHours)).GetEnumerator();
32+
public IEnumerator<(Day, SchoolHour[])> GetEnumerator() => SchoolDays.Keys.Zip(SchoolDays.Values, (day, schoolHours) => (day, schoolHours)).GetEnumerator();
4833

4934
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
5035
#endregion

0 commit comments

Comments
 (0)