Helper update

This commit is contained in:
BlubbFish 2011-10-09 18:48:00 +00:00
parent 5ebf0ad6a6
commit ce1cc70b15

View File

@ -11,15 +11,45 @@ namespace Matomat
{ {
class Helper class Helper
{ {
internal static double Serialize(string text) internal static string Serialize(LCDDisplay.Comport comport)
{ {
Stream stream = new MemoryStream(255); return comport.port + comport.bautrate.ToString() + comport.databits.ToString() + comport.parity.ToString() + comport.stopbits.ToString();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, text);
stream.Position = 0;
byte[] bytes = new byte[(int)stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
return BitConverter.ToDouble(bytes, 0);
} }
} }
public static class String
{
public static byte[] ToCharArray(this string str, string search, byte[] replace)
{
byte[] ret = new byte[str.Length];
for (int i = 0; i < str.Length; i++)
{
if (search.IndexOf(str.Substring(i, 1)) != -1)
{
ret[i] = replace[search.IndexOf(str.Substring(i, 1))];
}
else
{
ret[i] = Convert.ToByte(Convert.ToChar(str.Substring(i, 1)));
}
}
return ret;
}
}
public static class Array
{
public static byte[] Substring(this byte[] b, int start, int length)
{
byte[] ret = new byte[b.Length - start];
for (int i = start; (i < b.Length && i < start + length); i++)
{
ret[i - start] = b[i];
}
return ret;
}
public static byte[] Substring(this byte[] b, int start)
{
return b.Substring(start, b.Length);
}
}
} }