private object ConvertLocalToRemote(object srcValue, BuiltInType srcType, BuiltInType dstType)
{
// must determine the type from the source if the containing array is a variant.
if (srcType == BuiltInType.Variant)
{
TypeInfo typeInfo = TypeInfo.Construct(srcValue);
srcType = typeInfo.BuiltInType;
}
// no conversion by default.
object dstValue = srcValue;
// apply different conversions depending on the data type.
switch (dstType)
{
case BuiltInType.Guid:
{
dstValue = new Uuid((string)srcValue);
break;
}
case BuiltInType.XmlElement:
{
XmlDocument document = new XmlDocument();
document.InnerXml = (string)srcValue;
dstValue = document.DocumentElement;
break;
}
case BuiltInType.NodeId:
{
dstValue = GetRemoteNodeId((string)srcValue);
break;
}
case BuiltInType.ExpandedNodeId:
{
ExpandedNodeId nodeId = ExpandedNodeId.Parse((string)srcValue);
dstValue = GetRemoteExpandedNodeId(nodeId);
break;
}
case BuiltInType.QualifiedName:
{
dstValue = GetRemoteBrowseName((string)srcValue);
break;
}
case BuiltInType.LocalizedText:
{
dstValue = new LocalizedText((string)srcValue);
break;
}
case BuiltInType.StatusCode:
{
dstValue = new StatusCode((uint)srcValue);
break;
}
case BuiltInType.ExtensionObject:
{
BinaryDecoder decoder = new BinaryDecoder((byte[])srcValue, m_localMessageContext);
dstValue = decoder.ReadExtensionObject(null);
decoder.Close();
break;
}
default:
{
if (dstType != srcType && dstType != BuiltInType.Variant && dstType != BuiltInType.Null)
{
throw ComUtils.CreateComException(ResultIds.E_BADTYPE);
}
break;
}
}
// all done.
return dstValue;
}
#endregion