public virtual NodeState BindNodeStates(IDictionary <NodeId, IList <IReference> > externalReferences, NodeState nodeState, ref NodeStateCollection nodeStateCollectionToBind) { switch (nodeState.NodeClass) { case NodeClass.Object: if (!(nodeState is BaseObjectState baseObjectState)) { return(nodeState); } _previousBaseNode = baseObjectState; //Bind previous method now since it will be cleared if (_previousMethod != null) { int index = nodeStateCollectionToBind.FindIndex(x => x.NodeId == _previousMethod.NodeId); if (index == -1) { nodeStateCollectionToBind.Add(_previousMethod); } else { nodeStateCollectionToBind[index] = _previousMethod; } } // ensure the process object can be found via the server object. if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out IList <IReference> references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, _previousBaseNode.NodeId)); _previousMethod = null; break; case NodeClass.DataType: if (!(nodeState is DataTypeState dataTypeState)) { return(nodeState); } BindNodeStateActions(dataTypeState); _previousDataType = dataTypeState; int index2 = nodeStateCollectionToBind.FindIndex(x => x.NodeId == _previousDataType.NodeId); if (index2 == -1) { nodeStateCollectionToBind.Add(_previousDataType); } else { nodeStateCollectionToBind[index2] = _previousDataType; } break; case NodeClass.Method: if (!(nodeState is MethodState methodState)) { return(nodeState); } BindNodeStateActions(methodState); _previousBaseNode?.AddChild(methodState); if (_previousMethod != null) { int index = nodeStateCollectionToBind.FindIndex(x => x.NodeId == _previousMethod.NodeId); if (index == -1) { nodeStateCollectionToBind.Add(_previousMethod); } else { nodeStateCollectionToBind[index] = _previousMethod; } } _previousMethod = methodState; return(methodState); case NodeClass.Variable: if (_previousMethod != null) { if (!(nodeState is PropertyState propertyState)) { return(nodeState); } BindNodeStateActions(propertyState); if (propertyState.DisplayName == BrowseNames.InputArguments) { _previousMethod.InputArguments = new PropertyState <Argument[]>(_previousMethod) { NodeId = propertyState.NodeId, BrowseName = propertyState.BrowseName, DisplayName = propertyState.DisplayName, TypeDefinitionId = propertyState.TypeDefinitionId, ReferenceTypeId = propertyState.ReferenceTypeId, DataType = propertyState.DataType, ValueRank = propertyState.ValueRank, Value = ExtensionObject.ToArray(propertyState.Value, typeof(Argument)) as Argument[], OnReadUserAccessLevel = OnReadUserAccessLevel, OnSimpleWriteValue = OnWriteValue }; } else if (propertyState.DisplayName == BrowseNames.OutputArguments) { _previousMethod.OutputArguments = new PropertyState <Argument[]>(_previousMethod) { NodeId = propertyState.NodeId, BrowseName = propertyState.BrowseName, DisplayName = propertyState.DisplayName, TypeDefinitionId = propertyState.TypeDefinitionId, ReferenceTypeId = propertyState.ReferenceTypeId, DataType = propertyState.DataType, ValueRank = propertyState.ValueRank, Value = ExtensionObject.ToArray(propertyState.Value, typeof(Argument)) as Argument[], OnReadUserAccessLevel = OnReadUserAccessLevel, OnSimpleWriteValue = OnWriteValue }; } } break; default: if (_previousBaseNode != null) { int index = nodeStateCollectionToBind.FindIndex(x => x.NodeId == _previousBaseNode.NodeId); if (index == -1) { nodeStateCollectionToBind.Add(_previousBaseNode); } else { nodeStateCollectionToBind[index] = _previousBaseNode; } } if (_previousMethod != null) { int index = nodeStateCollectionToBind.FindIndex(x => x.NodeId == _previousMethod.NodeId); if (index == -1) { nodeStateCollectionToBind.Add(_previousMethod); } else { nodeStateCollectionToBind[index] = _previousMethod; } } _previousBaseNode = null; _previousMethod = null; break; } return(nodeState); }