Exemple #1
0
 internal DocumentField(DocumentFieldType valueType, string valueString, DateTimeOffset?valueDate, TimeSpan?valueTime, string valuePhoneNumber, double?valueNumber, int?valueInteger, V3SelectionMarkState?valueSelectionMarkPrivate, DocumentSignatureType?valueSignature, string valueCountryRegion, IReadOnlyList <DocumentField> valueArray, IReadOnlyDictionary <string, DocumentField> valueObject, CurrencyValue?valueCurrency, AddressValue valueAddress, string content, IReadOnlyList <BoundingRegion> boundingRegions, IReadOnlyList <DocumentSpan> spans, float?confidence)
 {
     ValueType                 = valueType;
     ValueString               = valueString;
     ValueDate                 = valueDate;
     ValueTime                 = valueTime;
     ValuePhoneNumber          = valuePhoneNumber;
     ValueNumber               = valueNumber;
     ValueInteger              = valueInteger;
     ValueSelectionMarkPrivate = valueSelectionMarkPrivate;
     ValueSignature            = valueSignature;
     ValueCountryRegion        = valueCountryRegion;
     ValueArray                = valueArray;
     ValueObject               = valueObject;
     ValueCurrency             = valueCurrency;
     ValueAddress              = valueAddress;
     Content         = content;
     BoundingRegions = boundingRegions;
     Spans           = spans;
     Confidence      = confidence;
 }
Exemple #2
0
        internal static DocumentField DeserializeDocumentField(JsonElement element)
        {
            DocumentFieldType                         type                      = default;
            Optional <string>                         valueString               = default;
            Optional <DateTimeOffset>                 valueDate                 = default;
            Optional <TimeSpan>                       valueTime                 = default;
            Optional <string>                         valuePhoneNumber          = default;
            Optional <double>                         valueNumber               = default;
            Optional <int>                            valueInteger              = default;
            Optional <V3SelectionMarkState>           valueSelectionMark        = default;
            Optional <DocumentSignatureType>          valueSignature            = default;
            Optional <string>                         valueCountryRegion        = default;
            Optional <IReadOnlyList <DocumentField> > valueArray                = default;
            Optional <IReadOnlyDictionary <string, DocumentField> > valueObject = default;
            Optional <CurrencyValue> valueCurrency = default;
            Optional <AddressValue>  valueAddress  = default;
            Optional <string>        content       = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            Optional <IReadOnlyList <DocumentSpan> >   spans           = default;
            Optional <float> confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString().ToDocumentFieldType();
                    continue;
                }
                if (property.NameEquals("valueString"))
                {
                    valueString = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueDate = property.Value.GetDateTimeOffset("D");
                    continue;
                }
                if (property.NameEquals("valueTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueTime = property.Value.GetTimeSpan("T");
                    continue;
                }
                if (property.NameEquals("valuePhoneNumber"))
                {
                    valuePhoneNumber = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueNumber"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueNumber = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("valueInteger"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueInteger = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("valueSelectionMark"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueSelectionMark = new V3SelectionMarkState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("valueSignature"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueSignature = new DocumentSignatureType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("valueCountryRegion"))
                {
                    valueCountryRegion = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueArray"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentField> array = new List <DocumentField>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DeserializeDocumentField(item));
                    }
                    valueArray = array;
                    continue;
                }
                if (property.NameEquals("valueObject"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, DocumentField> dictionary = new Dictionary <string, DocumentField>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, DeserializeDocumentField(property0.Value));
                    }
                    valueObject = dictionary;
                    continue;
                }
                if (property.NameEquals("valueCurrency"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueCurrency = CurrencyValue.DeserializeCurrencyValue(property.Value);
                    continue;
                }
                if (property.NameEquals("valueAddress"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueAddress = AddressValue.DeserializeAddressValue(property.Value);
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentField(type, valueString.Value, Optional.ToNullable(valueDate), Optional.ToNullable(valueTime), valuePhoneNumber.Value, Optional.ToNullable(valueNumber), Optional.ToNullable(valueInteger), Optional.ToNullable(valueSelectionMark), Optional.ToNullable(valueSignature), valueCountryRegion.Value, Optional.ToList(valueArray), Optional.ToDictionary(valueObject), Optional.ToNullable(valueCurrency), valueAddress.Value, content.Value, Optional.ToList(boundingRegions), Optional.ToList(spans), Optional.ToNullable(confidence)));
        }