ReadVariant() public method

Reads an Variant from the stream.
public ReadVariant ( string fieldName ) : Variant
fieldName string
return Variant
        /// <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();
        }
コード例 #2
0
ファイル: DataFileReader.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Extracts a BuiltInType value from the line.
        /// </summary>
        private bool ExtractField(int lineCount, ref string line, ServiceMessageContext context, BuiltInType valueType, out Variant value)
        {
            value = Variant.Null;
            string field = line;

            if (field == null)
            {
                return true;
            }

            if (valueType == BuiltInType.Null)
            {
                return true;
            }

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("<Value xmlns=\"{0}\">", Opc.Ua.Namespaces.OpcUaXsd);
            builder.AppendFormat("<{0}>", valueType);
            builder.Append(line);
            builder.AppendFormat("</{0}>", valueType);
            builder.Append("</Value>");

            XmlDocument document = new XmlDocument();
            document.InnerXml = builder.ToString();

            try
            {
                XmlDecoder decoder = new XmlDecoder(document.DocumentElement, context);
                value = decoder.ReadVariant(null);
            }
            catch (Exception e)
            {
                Utils.Trace("PARSE ERROR [Line:{0}] - '{1}': {2}", lineCount, field, e.Message);
                return false;
            }

            return true;
        }