using System;
namespace S7.Net.Types
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
public sealed class S7StringAttribute : Attribute
{
private readonly S7StringType type;
private readonly int reservedLength;
///
/// Initializes a new instance of the class.
///
/// The string type.
/// Reserved length of the string in characters.
/// Please use a valid value for the string type
public S7StringAttribute(S7StringType type, int reservedLength)
{
if (!Enum.IsDefined(typeof(S7StringType), type))
throw new ArgumentException("Please use a valid value for the string type");
this.type = type;
this.reservedLength = reservedLength;
}
///
/// Gets the type of the string.
///
///
/// The string type.
///
public S7StringType Type => type;
///
/// Gets the reserved length of the string in characters.
///
///
/// The reserved length of the string in characters.
///
public int ReservedLength => reservedLength;
///
/// Gets the reserved length in bytes.
///
///
/// The reserved length in bytes.
///
public int ReservedLengthInBytes => type == S7StringType.S7String ? reservedLength + 2 : (reservedLength * 2) + 4;
}
///
/// String type.
///
public enum S7StringType
{
///
/// ASCII string.
///
S7String = VarType.S7String,
///
/// Unicode string.
///
S7WString = VarType.S7WString
}
}