Opc.Ua.VariableTypeNode.Write C# (CSharp) Method

Write() protected method

Writes the value of an attribute.
protected Write ( uint attributeId, object value ) : ServiceResult
attributeId uint The attribute id.
value object The value.
return ServiceResult
        protected override ServiceResult Write(uint attributeId, object value)
        {
            switch (attributeId)
            {                    
                // values are copied when the are written so then can be safely returned on read.
                case Attributes.Value:
                {
                    m_value.Value = Utils.Clone(value);
                    return ServiceResult.Good;
                }

                case Attributes.DataType: 
                { 
                    NodeId dataType = (NodeId)value;

                    // must ensure the value is of the correct datatype.
                    if (dataType != m_dataType)
                    {
                        m_value.Value = null;
                    }

                    m_dataType = dataType;
                    return ServiceResult.Good;
                }
 
                case Attributes.ValueRank:
                {
                    int valueRank = (int)value;

                    if (valueRank != m_valueRank)
                    {
                        m_value.Value = null;
                    }

                    m_valueRank = valueRank;

                    return ServiceResult.Good;
                }
                    
                case Attributes.ArrayDimensions:
                {
                    m_arrayDimensions = new UInt32Collection((uint[])value);

                    // ensure number of dimensions is correct.
                    if (m_arrayDimensions.Count > 0)
                    {
                        if (m_valueRank != m_arrayDimensions.Count)
                        {                        
                            m_valueRank = m_arrayDimensions.Count;   
                            m_value.Value = null;
                        }
                    }

                    return ServiceResult.Good;
                }
            }

            return base.Write(attributeId, value);
        }
        #endregion