Opc.Ua.XmlEncoder.WriteVariant C# (CSharp) Method

WriteVariant() public method

Writes an Variant array to the stream.
public WriteVariant ( string fieldName, Variant value ) : void
fieldName string
value Variant
return void
        public void WriteVariant(string fieldName, Variant value)
        {
            if (BeginField(fieldName, false, false))
            {
                PushNamespace(Namespaces.OpcUaXsd);
                
                m_writer.WriteStartElement("Value", Namespaces.OpcUaXsd);                
                WriteVariantContents(value.Value, value.TypeInfo);                
                m_writer.WriteEndElement();
                
                PopNamespace();
                
                EndField(fieldName);
            }
        }
        

Usage Example

        /// <summary>
        /// Saves the attributes from the stream.
        /// </summary>
        /// <param name="context">The context for the system being accessed.</param>
        /// <param name="encoder">The encoder wrapping the stream to write.</param>
        public override void Save(ISystemContext context, XmlEncoder encoder)
        {
            base.Save(context, encoder);

            encoder.PushNamespace(Namespaces.OpcUaXsd);

            if (m_value != null)
            {
                encoder.WriteVariant("Value", WrappedValue);
            }

            if (!NodeId.IsNull(DataType))
            {
                encoder.WriteNodeId("DataType", DataType);
            }

            if (ValueRank != ValueRanks.Any)
            {
                encoder.WriteInt32("ValueRank", ValueRank);
            }

            if (ArrayDimensions != null)
            {
                encoder.WriteString("ArrayDimensions", BaseVariableState.ArrayDimensionsToXml(ArrayDimensions));
            }

            encoder.PopNamespace();
        }