From 5ef28a13eaa28988427943a2bcf61f1d7e46744d Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Mon, 10 Apr 2023 10:14:00 +0200 Subject: [PATCH] added MultiTerm.Protocols project, added ExtendedChar class --- MultiTerm.Protocols/Model/ExtendedChar.cs | 60 +++++++++++++++++++ .../MultiTerm.Protocols.csproj | 9 +++ MultiTerm.sln | 8 ++- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 MultiTerm.Protocols/Model/ExtendedChar.cs create mode 100644 MultiTerm.Protocols/MultiTerm.Protocols.csproj diff --git a/MultiTerm.Protocols/Model/ExtendedChar.cs b/MultiTerm.Protocols/Model/ExtendedChar.cs new file mode 100644 index 0000000..004c65a --- /dev/null +++ b/MultiTerm.Protocols/Model/ExtendedChar.cs @@ -0,0 +1,60 @@ +using System.Text; + +namespace MultiTerm.Protocols.Model; + +/// +/// A class that represents a Character and contains some additional information and methods. +/// The time of instanciation is represented with the property. +/// Several methods to display the Character in other formats than Unicode are provided. +/// +public class ExtendedChar +{ + /// + /// Data in the form of a character. UTF-16 code unit. + /// + public char Character { get; set; } + + /// + /// Time of instanciation of this class. + /// + public TimeOnly TimeOfCreation { get; private set; } + + public ExtendedChar() + { + // initialize time with now + this.TimeOfCreation = TimeOnly.FromDateTime(DateTime.Now); + } + + public override string ToString() + { + return this.ToUtf16String(); + } + + public string ToUtf16String() + { + return this.Character.ToString(); + } + + public string ToHexString() + { + // extract bytes from utf16 character + byte[] byteArray = Encoding.Unicode.GetBytes(this.ToUtf16String()); + + // convert to hexadecimal + return Convert.ToHexString(byteArray); + } + + public string ToBinaryString() + { + // extract bytes from utf16 character + byte[] byteArray = Encoding.Unicode.GetBytes(this.ToUtf16String()); + + // foreach byte convert to binary and add to string + string binaryString = String.Empty; + foreach (byte b in byteArray) + { + binaryString += $"{Convert.ToString(b, 2)} "; + } + return binaryString; + } +} diff --git a/MultiTerm.Protocols/MultiTerm.Protocols.csproj b/MultiTerm.Protocols/MultiTerm.Protocols.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/MultiTerm.Protocols/MultiTerm.Protocols.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/MultiTerm.sln b/MultiTerm.sln index d80e7c1..727e8e6 100644 --- a/MultiTerm.sln +++ b/MultiTerm.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiTerm.Core", "MultiTerm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{26454190-1B60-46BE-8234-3207FB00D8A4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiTerm.Wpf.CustomControl", "MultiTerm.Wpf.CustomControl\MultiTerm.Wpf.CustomControl.csproj", "{9E308B45-2F71-44DD-A640-40953FD644D7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiTerm.Wpf.CustomControl", "MultiTerm.Wpf.CustomControl\MultiTerm.Wpf.CustomControl.csproj", "{9E308B45-2F71-44DD-A640-40953FD644D7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiTerm.Protocols", "MultiTerm.Protocols\MultiTerm.Protocols.csproj", "{D35B996A-91EE-4A6A-BA82-C74684AF4572}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {9E308B45-2F71-44DD-A640-40953FD644D7}.Debug|Any CPU.Build.0 = Debug|Any CPU {9E308B45-2F71-44DD-A640-40953FD644D7}.Release|Any CPU.ActiveCfg = Release|Any CPU {9E308B45-2F71-44DD-A640-40953FD644D7}.Release|Any CPU.Build.0 = Release|Any CPU + {D35B996A-91EE-4A6A-BA82-C74684AF4572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D35B996A-91EE-4A6A-BA82-C74684AF4572}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D35B996A-91EE-4A6A-BA82-C74684AF4572}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D35B996A-91EE-4A6A-BA82-C74684AF4572}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE