Opc.Ua.ClientBase.ValidateDataValue C# (CSharp) Method

ValidateDataValue() public static method

Validates a DataValue returned from the server.
public static ValidateDataValue ( Opc.Ua.DataValue value, Type expectedType, int index, DiagnosticInfoCollection diagnosticInfos, ResponseHeader responseHeader ) : ServiceResult
value Opc.Ua.DataValue The value.
expectedType System.Type The expected type.
index int The index.
diagnosticInfos DiagnosticInfoCollection The diagnostic information.
responseHeader ResponseHeader The response header.
return ServiceResult
        public static ServiceResult ValidateDataValue(
            DataValue value,
            Type expectedType,
            int index,
            DiagnosticInfoCollection diagnosticInfos,
            ResponseHeader responseHeader)
        {
            // check for null.
            if (value == null)
            {
                return new ServiceResult(StatusCodes.BadUnexpectedError, "The server returned a value for a data value.");
            }

            // check status code.
            if (StatusCode.IsBad(value.StatusCode))
            {
                return GetResult(value.StatusCode, index, diagnosticInfos, responseHeader);
            }

            // check data type.
            if (expectedType != null)
            {
                if (!expectedType.IsInstanceOfType(value.Value))
                {
                    return ServiceResult.Create(
                        StatusCodes.BadUnexpectedError,
                        "The server returned data value of type {0} when a value of type {1} was expected.",
                        (value.Value != null) ? value.Value.GetType().Name : "(null)",
                        expectedType.Name);
                }
            }

            return null;
        }
        #endregion