Opc.Ua.VariableNode.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)
            {
                case Attributes.AccessLevel:             { m_accessLevel             = (byte)value;   return ServiceResult.Good; } 
                case Attributes.UserAccessLevel:         { m_userAccessLevel         = (byte)value;   return ServiceResult.Good; } 
                case Attributes.MinimumSamplingInterval: { m_minimumSamplingInterval = (int)value;    return ServiceResult.Good; } 
                case Attributes.Historizing:             { m_historizing             = (bool)value;   return ServiceResult.Good; } 
                    
                // 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 = TypeInfo.GetDefaultValue(dataType, m_valueRank);
                    }

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

                    if (valueRank != m_valueRank)
                    {
                        m_value.Value = TypeInfo.GetDefaultValue(m_dataType, valueRank);
                    }

                    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_arrayDimensions.Count != m_valueRank)
                        {
                            m_valueRank = m_arrayDimensions.Count;
                            m_value.Value = TypeInfo.GetDefaultValue(m_dataType, m_valueRank);
                        }
                    }

                    return ServiceResult.Good;
                }
            }

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