added comments to message

This commit is contained in:
Sem van der Hoeven
2020-09-23 11:57:20 +02:00
parent 603703b3f6
commit 31ef1beb82

59
Message/Message.cs Normal file
View File

@@ -0,0 +1,59 @@
using Newtonsoft.Json;
using System;
namespace Message
{
/// <summary>
/// Message class to handle traffic between clients and server
/// </summary>
public class Message
{
/// <summary>
/// identifier for the message
/// </summary>
public string Identifier
{
get;set;
}
/// <summary>
/// payload of the message, the actual text
/// </summary>
public string Payload
{
get;set;
}
/// <summary>
/// constructs a new message with the given parameters
/// </summary>
/// <param name="identifier">the identifier</param>
/// <param name="payload">the payload</param>
public Message(string identifier, string payload)
{
this.Identifier = identifier;
this.Payload = payload;
}
/// <summary>
/// serializes this object to a JSON string
/// </summary>
/// <returns>a JSON representation of this object</returns>
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
/// <summary>
/// deserializes a JSON string into a new Message object
/// </summary>
/// <param name="json">the JSON string to deserialize</param>
/// <returns>a new <c>Message</c> object from the JSON string</returns>
public static Message Deserialize(string json)
{
return (Message)JsonConvert.DeserializeObject(json);
}
}
}