Opc.Ua.XmlDecoder.ReadInt32 C# (CSharp) Method

ReadInt32() public method

Reads an int from the stream.
public ReadInt32 ( string fieldName ) : int
fieldName string
return int
        public int ReadInt32(string fieldName)
        {
            if (BeginField(fieldName, true))
            {
                string xml = ReadString();
                
                if (!String.IsNullOrEmpty(xml))
                {
                    int value = XmlConvert.ToInt32(xml);
                    EndField(fieldName);
                    return value;
                }
            }

            return 0;
        }
        

Usage Example

        /// <summary>
        /// Updates the attributes from the stream.
        /// </summary>
        /// <param name="context">The context for the system being accessed.</param>
        /// <param name="decoder">The decoder wrapping the stream to read.</param>
        public override void Update(ISystemContext context, XmlDecoder decoder)
        {
            base.Update(context, decoder);

            decoder.PushNamespace(Namespaces.OpcUaXsd);

            if (decoder.Peek("Value"))
            {
                WrappedValue = decoder.ReadVariant("Value");
            }

            if (decoder.Peek("DataType"))
            {
                DataType = decoder.ReadNodeId("DataType");
            }

            if (decoder.Peek("ValueRank"))
            {
                ValueRank = decoder.ReadInt32("ValueRank");
            }

            if (decoder.Peek("ArrayDimensions"))
            {
                ArrayDimensions = BaseVariableState.ArrayDimensionsFromXml(decoder.ReadString("ArrayDimensions"));
            }

            decoder.PopNamespace();
        }