Skip to content

Commit a042187

Browse files
committed
Attachments are now ReadOnly.
1 parent 51a1a34 commit a042187

22 files changed

+44
-34
lines changed

bin/MataSharp.XML

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/MataSharp.dll

512 Bytes
Binary file not shown.

src/MataSharp/Assignment.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Globalization;
56
using Newtonsoft.Json;
@@ -12,7 +13,7 @@ public partial class Assignment : IComparable<Assignment>
1213
public string Description { get; set; }
1314
public uint? Grade { get; set; }
1415
public string Class { get; set; }
15-
public List<Attachment> Attachments { get; set; }
16+
public ReadOnlyCollection<Attachment> Attachments { get; set; }
1617
public List<MagisterPerson> Teachers { get; set; }
1718
public int ID { get; set; }
1819
public DateTime HandInTime { get; set; }
@@ -37,10 +38,10 @@ public partial class AssignmentVersion
3738
public string Name { get; set; }
3839
public uint? Grade { get; set; }
3940
public string TeacherNotice { get; set; }
40-
public List<Attachment> FeedbackAttachments { get; set; }
41+
public ReadOnlyCollection<Attachment> FeedbackAttachments { get; set; }
4142
public DateTime DeadLine { get; set; }
4243
public DateTime HandInTime { get; set; }
43-
public List<Attachment> HandedInAttachments { get; set; }
44+
public ReadOnlyCollection<Attachment> HandedInAttachments { get; set; }
4445
public string HandedInFooter { get; set; }
4546

4647
public override string ToString() { return this.Name; }

src/MataSharp/Conversions.cs renamed to src/MataSharp/Extensions.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Globalization;
45

56
namespace MataSharp
67
{
7-
internal static class Conversions
8+
public static class Extensions
89
{
910
/// <summary>
1011
/// Converts the current string to a DateTime.
1112
/// </summary>
1213
/// <returns>The string parsed as DateTime</returns>
13-
public static DateTime ToDateTime(this String original)
14+
internal static DateTime ToDateTime(this String original)
1415
{
1516
return (!string.IsNullOrWhiteSpace(original)) ? DateTime.Parse(original, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : new DateTime();
1617
}
@@ -20,18 +21,18 @@ public static DateTime ToDateTime(this String original)
2021
/// </summary>
2122
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
2223
/// <returns>The array as list</returns>
23-
internal static List<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
24+
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
2425
{
2526
var tmpList = new List<Attachment>(currentArray);
2627
tmpList.ForEach(a => a.Type = AttachmentType);
27-
return tmpList;
28+
return new ReadOnlyCollection<Attachment>(tmpList);
2829
}
2930

3031
/// <summary>
3132
/// Converts the current DateTime instance to a string.
3233
/// </summary>
3334
/// <returns>The current DateTime instance as string.</returns>
34-
public static string ToUTCString(this DateTime original)
35+
internal static string ToUTCString(this DateTime original)
3536
{
3637
return original.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z");
3738
}
@@ -40,7 +41,7 @@ public static string ToUTCString(this DateTime original)
4041
/// Gets the DayOfWeek from the current DateTime instance in Dutch.
4142
/// </summary>
4243
/// <returns>Dutch day of week that represents the day of the current DateTime instance.</returns>
43-
public static string DayOfWeekDutch(this DateTime Date)
44+
internal static string DayOfWeekDutch(this DateTime Date)
4445
{
4546
switch(Date.DayOfWeek)
4647
{
@@ -60,9 +61,14 @@ public static string DayOfWeekDutch(this DateTime Date)
6061
/// </summary>
6162
/// <param name="dutch">If the day should be in Dutch or in English</param>
6263
/// <returns>The current DateTime instance as a string.</returns>
63-
public static string ToString(this DateTime Date, bool dutch)
64+
internal static string ToString(this DateTime Date, bool dutch)
6465
{
6566
return (dutch) ? (Date.DayOfWeekDutch() + " " + Date.ToString()) : (Date.DayOfWeek + " " + Date.ToString());
6667
}
68+
69+
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
70+
{
71+
foreach (var item in current) action(item);
72+
}
6773
}
6874
}

src/MataSharp/MagisterMessage.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Newtonsoft.Json;
55
using System.Globalization;
66
using System.Text.RegularExpressions;
7+
using System.Collections.ObjectModel;
78

89
namespace MataSharp
910
{
@@ -37,7 +38,7 @@ public bool IsRead
3738
public bool IsFlagged { get; set; }
3839
public int? IDOriginal { get; set; }
3940
public int? IDOrginalReceiver { get; set; }
40-
public List<Attachment> Attachments { get; internal set; }
41+
public ReadOnlyCollection<Attachment> Attachments { get; internal set; }
4142
internal int _Folder { get; set; }
4243

4344
public MessageFolder Folder
@@ -127,7 +128,7 @@ public MagisterMessage CreateForwardMessage()
127128
{
128129
Sender = this.Sender,//Magister's logic
129130
_Folder = this._Folder,
130-
Attachments = new List<Attachment>(),
131+
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
131132
CC = null,
132133
IsFlagged = this.IsFlagged,
133134
ID = this.ID,
@@ -160,7 +161,7 @@ public MagisterMessage CreateForwardMessage(string ContentAdd)
160161
{
161162
Sender = this.Sender,//Magister's logic
162163
_Folder = this._Folder,
163-
Attachments = new List<Attachment>(),
164+
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
164165
IsFlagged = this.IsFlagged,
165166
ID = this.ID,
166167
SenderGroupID = 4,
@@ -188,15 +189,15 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
188189
{
189190
var tmpSubject = (this.Subject[0] != 'R' || this.Subject[1] != 'E' || this.Subject[2] != ':' || this.Subject[3] != ' ') ? "RE: " + this.Subject : this.Subject;
190191

191-
var tmpCC = this.Recipients.ToList().Where(p => p.ID != this.Mata.Person.ID).ToList(); //Should get the current receivers and pull itself out. :)
192-
if (this.CC != null) tmpCC.AddRange(this.CC.ToList().Where(p => p.ID != this.Mata.Person.ID));
192+
var tmpCC = this.Recipients.Where(p => p.ID != this.Mata.Person.ID).ToList(); //Should get the current receivers and pull itself out. :)
193+
if (this.CC != null) tmpCC.AddRange(this.CC.Where(p => p.ID != this.Mata.Person.ID));
193194
tmpCC.Sort();
194195

195196
return new MagisterMessage()
196197
{
197198
Sender = this.Sender,
198199
_Folder = this._Folder,
199-
Attachments = new List<Attachment>(),
200+
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
200201
CC = tmpCC,
201202
IsFlagged = this.IsFlagged,
202203
ID = this.ID,
@@ -229,7 +230,7 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
229230
{
230231
Sender = this.Sender,//Magister's logic
231232
_Folder = this._Folder,
232-
Attachments = new List<Attachment>(),
233+
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
233234
CC = null,
234235
IsFlagged = this.IsFlagged,
235236
ID = this.ID,

src/MataSharp/MataSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<ItemGroup>
5353
<Compile Include="Assignment.cs" />
5454
<Compile Include="Attachment.cs" />
55-
<Compile Include="Conversions.cs" />
55+
<Compile Include="Extensions.cs" />
5656
<Compile Include="DigitalSchoolUtilities.cs" />
5757
<Compile Include="Homework.cs" />
5858
<Compile Include="MessageFolder.cs" />

src/MataSharp/StudyGuide.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using Newtonsoft.Json;
44
using System.Globalization;
5+
using System.Collections.ObjectModel;
56

67
namespace MataSharp
78
{
@@ -25,7 +26,7 @@ public int CompareTo(StudyGuide other)
2526

2627
public partial class StudyGuidePart : IComparable<StudyGuidePart>
2728
{
28-
public List<Attachment> Attachments { get; set; }
29+
public ReadOnlyCollection<Attachment> Attachments { get; set; }
2930
public int ID { get; set; }
3031
public bool Visible { get; set; }
3132
public string Description { get; set; }

src/MataSharp/bin/Release/MataSharp.XML

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)