public void WriteArray()

in src/Azure.IIoT.OpcUa/src/Encoders/JsonEncoderEx.cs [1866:1993]


        public void WriteArray(string fieldName, object array, int valueRank,
            BuiltInType builtInType)
        {
            // write array.
            if (valueRank == ValueRanks.OneDimension)
            {
                switch (builtInType)
                {
                    case BuiltInType.Boolean:
                        WriteBooleanArray(fieldName, (bool[])array);
                        return;
                    case BuiltInType.SByte:
                        WriteSByteArray(fieldName, (sbyte[])array);
                        return;
                    case BuiltInType.Byte:
                        WriteByteArray(fieldName, (byte[])array);
                        return;
                    case BuiltInType.Int16:
                        WriteInt16Array(fieldName, (short[])array);
                        return;
                    case BuiltInType.UInt16:
                        WriteUInt16Array(fieldName, (ushort[])array);
                        return;
                    case BuiltInType.Int32:
                        WriteInt32Array(fieldName, (int[])array);
                        return;
                    case BuiltInType.UInt32:
                        WriteUInt32Array(fieldName, (uint[])array);
                        return;
                    case BuiltInType.Int64:
                        WriteInt64Array(fieldName, (long[])array);
                        return;
                    case BuiltInType.UInt64:
                        WriteUInt64Array(fieldName, (ulong[])array);
                        return;
                    case BuiltInType.Float:
                        WriteFloatArray(fieldName, (float[])array);
                        return;
                    case BuiltInType.Double:
                        WriteDoubleArray(fieldName, (double[])array);
                        return;
                    case BuiltInType.String:
                        WriteStringArray(fieldName, (string[])array);
                        return;
                    case BuiltInType.DateTime:
                        WriteDateTimeArray(fieldName, (DateTime[])array);
                        return;
                    case BuiltInType.Guid:
                        WriteGuidArray(fieldName, (Uuid[])array);
                        return;
                    case BuiltInType.ByteString:
                        WriteByteStringArray(fieldName, (byte[][])array);
                        return;
                    case BuiltInType.XmlElement:
                        WriteXmlElementArray(fieldName, (XmlElement[])array);
                        return;
                    case BuiltInType.NodeId:
                        WriteNodeIdArray(fieldName, (NodeId[])array);
                        return;
                    case BuiltInType.ExpandedNodeId:
                        WriteExpandedNodeIdArray(fieldName, (ExpandedNodeId[])array);
                        return;
                    case BuiltInType.StatusCode:
                        WriteStatusCodeArray(fieldName, (StatusCode[])array);
                        return;
                    case BuiltInType.QualifiedName:
                        WriteQualifiedNameArray(fieldName, (QualifiedName[])array);
                        return;
                    case BuiltInType.LocalizedText:
                        WriteLocalizedTextArray(fieldName, (LocalizedText[])array);
                        return;
                    case BuiltInType.ExtensionObject:
                        WriteExtensionObjectArray(fieldName, (ExtensionObject[])array);
                        return;
                    case BuiltInType.DataValue:
                        WriteDataValueArray(fieldName, (DataValue[])array);
                        return;
                    case BuiltInType.DiagnosticInfo:
                        WriteDiagnosticInfoArray(fieldName, (DiagnosticInfo[])array);
                        return;
                    case BuiltInType.Enumeration:
                        if (array is not Array enumArray)
                        {
                            throw new EncodingException(
                                "Unexpected non Array type encountered while encoding an array of enumeration.");
                        }
                        var enumType = enumArray.GetType().GetElementType();
                        Debug.Assert(enumType != null);
                        WriteEnumeratedArray(fieldName, enumArray, enumType);
                        return;
                    case BuiltInType.Variant:
                    default:
                        if (array is IEncodeable[] encodeables)
                        {
                            var elementType = array.GetType().GetElementType();
                            if (elementType != null)
                            {
                                WriteEncodeableArray(fieldName, encodeables, elementType);
                                return;
                            }
                        }
                        switch (array)
                        {
                            case Variant[] variants:
                                WriteVariantArray(fieldName, variants);
                                return;
                            case object[] objects:
                                WriteObjectArray(fieldName, objects);
                                return;
                            case null:
                                WriteObjectArray(fieldName, null);
                                return;
                        }
                        throw new EncodingException("Unexpected type encountered " +
                            $"while encoding an array of Variants: {array.GetType()}");
                }
            }
            // write matrix.
            else if (valueRank > ValueRanks.OneDimension)
            {
                if (array is Matrix matrix)
                {
                    var index = 0;
                    WriteStructureMatrix(fieldName, matrix, 0, ref index, matrix.TypeInfo);
                    return;
                }
            }
        }