why: DataWriter : IDisposable
if you dont dispose anything in the class ? :D
you could at least write:
yo could do:
For your read i would rather use it more generic
the reason is, you could send and read custom types and convert them, with your method you are stuck to what you provide and you have to extend the class all the time...
just suggestions - if i am wrong or you have different reasons feel free to express them and explain it to me :)
P.S. to send custom types/classes you need to restructure the code a bit more and use
BinaryFormatter / serialization blabla blupp .. google is our friend :)
if you dont dispose anything in the class ? :D
you could at least write:
PHP Code
<?php
/// <summary>
/// Dispose of this object, freeing up all used memory.
/// </summary>
public void Dispose()
{
if(array==null)return;
array.clear();
array=null;
}
yo could do:
PHP Code
<?php
/// <summary>
/// Adds the data onto the byte array, in T form.
/// </summary>
/// <param name="data">The data to add onto the array.</param>
public void Write<T>(T data)
{
if(typeof(T)==typeof(string))
array.AddRange(ASCIIEncoding.Default.GetBytes(data));
else
array.AddRange(BitConverter.GetBytes(data));
}
For your read i would rather use it more generic
PHP Code
<?php
//pseudo code
public byte[] Read<T>()
{
List<T> bytes = new List<T>();
for(var i = 0; i<sizeof(T);i++)
{
bytes.Add(_stream.ReadByte());
}
return bytes.ToArray();
}
the reason is, you could send and read custom types and convert them, with your method you are stuck to what you provide and you have to extend the class all the time...
just suggestions - if i am wrong or you have different reasons feel free to express them and explain it to me :)
P.S. to send custom types/classes you need to restructure the code a bit more and use
BinaryFormatter / serialization blabla blupp .. google is our friend :)
