Treat you custom strings as nested UDTs. Here is an example class for String20 that will make things easier:
class String20
{
public int Length;
public System.SByte[] Characters;
public String20()
{
Characters = new System.SByte[20];
}
public String20(string value) : this()
{
SetValue(value);
}
public void SetValue(string value)
{
Length =Math.Min(20, value.Length);
if (value.Length >20)
{
value = value.Substring(0, 20);
}
// WriteUDT does not support byte, so we have to do a little rework here
byte[] TmpArray= new byte[20];
System.Text.ASCIIEncoding.ASCII.GetBytes(value).CopyTo(TmpArray, 0);
Characters = (sbyte[])(Array)TmpArray;
}
}
Then in your class, you would change this:
public String20 ProductID { get; set; };
Then you can set the value as such:
ProductID = new String20("TheValue");
I have not tested this, so it may not work the first try, but should get quite close.