added MultiTerm.Protocols project,

added ExtendedChar class
master
Jonas Arnold 3 years ago
parent 95a9eec8e4
commit 5ef28a13ea
  1. 60
      MultiTerm.Protocols/Model/ExtendedChar.cs
  2. 9
      MultiTerm.Protocols/MultiTerm.Protocols.csproj
  3. 8
      MultiTerm.sln

@ -0,0 +1,60 @@
using System.Text;
namespace MultiTerm.Protocols.Model;
/// <summary>
/// A class that represents a Character and contains some additional information and methods.
/// The time of instanciation is represented with the <see cref="TimeOfCreation"/> property.
/// Several methods to display the Character in other formats than Unicode are provided.
/// </summary>
public class ExtendedChar
{
/// <summary>
/// Data in the form of a character. UTF-16 code unit.
/// </summary>
public char Character { get; set; }
/// <summary>
/// Time of instanciation of this class.
/// </summary>
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;
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiTerm.Core", "MultiTerm
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{26454190-1B60-46BE-8234-3207FB00D8A4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{26454190-1B60-46BE-8234-3207FB00D8A4}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{9E308B45-2F71-44DD-A640-40953FD644D7}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save