public void WriteEncodeableArray(string fieldName, IList<IEncodeable> values, System.Type systemType)
{
if (BeginField(fieldName, values == null, true))
{
// check the length.
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
{
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
}
// get name for type being encoded.
XmlQualifiedName xmlName = EncodeableFactory.GetXmlName(systemType);
if (xmlName == null)
{
xmlName = new XmlQualifiedName("IEncodeable", Namespaces.OpcUaXsd);
}
PushNamespace(xmlName.Namespace);
// encode each element in the array.
for (int ii = 0; ii < values.Count; ii++)
{
IEncodeable value = values[ii];
if (systemType != null)
{
if (!systemType.IsInstanceOfType(value))
{
throw new ServiceResultException(
StatusCodes.BadEncodingError,
Utils.Format("Objects with type '{0}' are not allowed in the array being serialized.", systemType.FullName));
}
WriteEncodeable(xmlName.Name, value, systemType);
}
}
PopNamespace();
EndField(fieldName);
}
}