ChatHere: Messagecode

Heb net weer wat zitten werken aan m’n ChatHere App, even uitgezocht hoe delegates werken (leuk spul! Makkelijk om u code clean te houden).

Net ook even een Message class geschreven, deze wordt geserialized naar een memorystream, en dan zo naar de socket gestuurd.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.Serialization;

namespace ChatHere
{
	///

	/// Class for holding the message
	/// 

	class Message : ISerializable
	{
		private String nick;
		private String message;
		private Font font;

		///

		/// Cosntructor
		/// 

		///
The nick
		///
The message
		///
The font
		public Message(String nick, String message, Font font)
		{
			this.nick = nick;
			this.message = message;
			this.font = font;
		}

		///

		/// The constructor for after deserialization
		/// 

		///

		///

		public Message(SerializationInfo info, StreamingContext context)
			: this ((String)info.GetString("nick"), (String)info.GetString("message"), (Font)info.GetValue("font", typeof(Font)))
		{
		}

		#region ISerializable Members

		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("nick", this.nick, typeof(String));
			info.AddValue("message", this.message, typeof(String));
			info.AddValue("font", this.font, typeof(Font));
		}

		#endregion
	}
}

Indien iemand anders misschien tips heeft, feel free to post them.

One thought on “ChatHere: Messagecode

  1. Voor die simpele serializatie moet je helemaal niet ISerialize implementeren. Je hebt geen speciale serializatie – logic.
    Gewoon je class decoreren met het [Serializable] attribute is voldoende.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>