Exemplo n.º 1
0
        private bool DetermineExtensionDataProperty(Dictionary <string, JsonPropertyInfo> cache)
        {
            JsonPropertyInfo?jsonPropertyInfo = GetPropertyWithUniqueAttribute(typeof(JsonExtensionDataAttribute), cache);

            if (jsonPropertyInfo != null)
            {
                Type declaredPropertyType = jsonPropertyInfo.DeclaredPropertyType;
                if (typeof(IDictionary <string, object>).IsAssignableFrom(declaredPropertyType) ||
                    typeof(IDictionary <string, JsonElement>).IsAssignableFrom(declaredPropertyType))
                {
                    JsonConverter converter = Options.GetConverter(declaredPropertyType);
                    Debug.Assert(converter != null);
                }
                else
                {
                    ThrowHelper.ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(this, jsonPropertyInfo);
                }

                DataExtensionProperty = jsonPropertyInfo;

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private static void WriteExtensionData(Utf8JsonWriter writer, ref WriteStackFrame frame)
        {
            DictionaryEntry entry = ((IDictionaryEnumerator)frame.Enumerator).Entry;

            if (entry.Value is JsonElement element)
            {
                Debug.Assert(entry.Key is string);

                string propertyName = (string)entry.Key;
                element.WriteProperty(propertyName, writer);
            }
            else
            {
                ThrowHelper.ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(frame.JsonClassInfo, entry.Value.GetType());
            }
        }
Exemplo n.º 3
0
        private void DetermineExtensionDataProperty()
        {
            JsonPropertyInfo jsonPropertyInfo = GetPropertyThatHasAttribute(typeof(JsonExtensionDataAttribute));

            if (jsonPropertyInfo != null)
            {
                Type declaredPropertyType = jsonPropertyInfo.DeclaredPropertyType;
                if (!typeof(IDictionary <string, JsonElement>).IsAssignableFrom(declaredPropertyType) &&
                    !typeof(IDictionary <string, object>).IsAssignableFrom(declaredPropertyType))
                {
                    ThrowHelper.ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(this, jsonPropertyInfo);
                }

                DataExtensionProperty = jsonPropertyInfo;
            }
        }