|
using System;
using System.Text;
namespace YAMP
{
public class StringValue : Value
{
#region Members
string _value;
#endregion
#region Properties
public string Value
{
get { return _value; }
}
public int Length
{
get { return _value.Length; }
}
#endregion
#region implemented abstract members of Value
public override Value Add (Value right)
{
return new StringValue(_value + right.ToString());
}
public override Value Subtract (Value right)
{
throw new OperationNotSupportedException("-", this);
}
public override Value Multiply (Value right)
{
throw new OperationNotSupportedException("*", this);
}
public override Value Divide (Value denominator)
{
throw new OperationNotSupportedException("/", this);
}
public override Value Power (Value exponent)
{
throw new OperationNotSupportedException("^", this);
}
public override byte[] Serialize ()
{
var content = Encoding.Unicode.GetBytes(_value);
var length = BitConverter.GetBytes(content.Length);
var value = new byte[length.Length + content.Length];
length.CopyTo(value, 0);
content.CopyTo(value, length.Length);
return value;
}
public override Value Deserialize (byte[] content)
{
var length = BitConverter.ToInt32(content, 0);
_value = Encoding.Unicode.GetString(content, 4, length);
return this;
}
#endregion
#region ctor
public StringValue () : this(string.Empty)
{
}
public StringValue (string value)
{
_value = value;
}
#endregion
#region Overrides
public override string ToString ()
{
return _value;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.
During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.
Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.