/// <summary> /// Recursively imports any NodeIds or ExpandedNodeIds contained in a value. /// </summary> /// <param name="value">The value.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <param name="serverUris">The server URIs.</param> /// <returns></returns> private object ImportValue(object value, NamespaceTable namespaceUris, StringTable serverUris) { Array array = value as Array; if (array != null) { Type elementType = array.GetType().GetElementType(); if (elementType != typeof(NodeId) && elementType != typeof(ExpandedNodeId) && elementType != typeof(object) && elementType != typeof(ExtensionObject)) { return(array); } Array copy = Array.CreateInstance(elementType, array.Length); for (int ii = 0; ii < array.Length; ii++) { copy.SetValue(ImportValue(array.GetValue(ii), namespaceUris, serverUris), ii); } return(copy); } NodeId nodeId = value as NodeId; if (nodeId != null) { return(Import(nodeId, namespaceUris)); } ExpandedNodeId expandedNodeId = value as ExpandedNodeId; if (expandedNodeId != null) { return(Import(expandedNodeId, namespaceUris, serverUris)); } ExtensionObject extension = value as ExtensionObject; if (extension != null) { Argument argument = ExtensionObject.ToEncodeable(extension) as Argument; if (argument != null) { argument.DataType = Import(argument.DataType, namespaceUris); } } return(value); }
/// <summary> /// Translates a value. /// </summary> /// <param name="value">The value.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <param name="serverUris">The server URIs.</param> /// <returns>Translated value.</returns> private object TranslateValue(object value, NamespaceTable namespaceUris, StringTable serverUris) { TypeInfo typeInfo = TypeInfo.Construct(value); // do nothing for unknown types. if (typeInfo == null) { return(value); } // recursively process array values. if (typeInfo.ValueRank > 0) { TranslateArrayValue((Array)value, typeInfo.BuiltInType, namespaceUris, serverUris); return(value); } // check for values containing namespace indexes. switch (typeInfo.BuiltInType) { case BuiltInType.NodeId: { return(Translate((NodeId)value, m_namespaceUris, namespaceUris)); } case BuiltInType.ExpandedNodeId: { return(Translate((ExpandedNodeId)value, m_namespaceUris, m_serverUris, namespaceUris, serverUris)); } case BuiltInType.QualifiedName: { return(Translate((QualifiedName)value, m_namespaceUris, namespaceUris)); } case BuiltInType.ExtensionObject: { Argument argument = ExtensionObject.ToEncodeable((ExtensionObject)value) as Argument; if (argument != null) { argument.DataType = Translate(argument.DataType, m_namespaceUris, namespaceUris); } return(value); } } return(value); }