コード例 #1
0
 public ParameterLookupValue(JsonPropertyInfo jsonPropertyInfo)
 {
     JsonPropertyInfo = jsonPropertyInfo;
 }
コード例 #2
0
        // Create a parameter that is ignored at run time. It uses the same type (typeof(sbyte)) to help
        // prevent issues with unsupported types and helps ensure we don't accidently (de)serialize it.
        public static JsonParameterInfo CreateIgnoredParameterPlaceholder(JsonParameterInfoValues parameterInfo, JsonPropertyInfo matchingProperty)
        {
            JsonParameterInfo jsonParameterInfo = matchingProperty.ConverterBase.CreateJsonParameterInfo();

            jsonParameterInfo.ClrInfo             = parameterInfo;
            jsonParameterInfo.RuntimePropertyType = matchingProperty.RuntimePropertyType !;
            jsonParameterInfo.NameAsUtf8Bytes     = matchingProperty.NameAsUtf8Bytes !;
            jsonParameterInfo.InitializeDefaultValue(matchingProperty);
            return(jsonParameterInfo);
        }
コード例 #3
0
 public override void Initialize(JsonParameterInfoValues parameterInfo, JsonPropertyInfo matchingProperty, JsonSerializerOptions options)
 {
     base.Initialize(parameterInfo, matchingProperty, options);
     InitializeDefaultValue(matchingProperty);
 }
コード例 #4
0
 protected abstract void InitializeDefaultValue(JsonPropertyInfo matchingProperty);
コード例 #5
0
        internal void AddPropertiesUsingSourceGenInfo()
        {
            if (PropertyInfoForTypeInfo.ConverterStrategy != ConverterStrategy.Object)
            {
                return;
            }

            JsonSerializerContext?context = Options.SerializerContext;

            JsonPropertyInfo[] array;
            if (PropInitFunc == null || (array = PropInitFunc(context !)) == null)
            {
                if (typeof(T) == typeof(object))
                {
                    return;
                }

                if (Converter.ElementType != null)
                {
                    // Nullable<> or F# optional converter's strategy is set to element's strategy
                    return;
                }

                if (SerializeHandler != null && Options.SerializerContext?.CanUseSerializationLogic == true)
                {
                    ThrowOnDeserialize = true;
                    return;
                }

                ThrowHelper.ThrowInvalidOperationException_NoMetadataForTypeProperties(context, Type);
                return;
            }

            Dictionary <string, JsonPropertyInfo>?    ignoredMembers = null;
            JsonPropertyDictionary <JsonPropertyInfo> propertyCache  = CreatePropertyCache(capacity: array.Length);

            for (int i = 0; i < array.Length; i++)
            {
                JsonPropertyInfo jsonPropertyInfo = array[i];
                bool             hasJsonInclude   = jsonPropertyInfo.SrcGen_HasJsonInclude;

                if (!jsonPropertyInfo.SrcGen_IsPublic)
                {
                    if (hasJsonInclude)
                    {
                        Debug.Assert(jsonPropertyInfo.ClrName != null, "ClrName is not set by source gen");
                        ThrowHelper.ThrowInvalidOperationException_JsonIncludeOnNonPublicInvalid(jsonPropertyInfo.ClrName, jsonPropertyInfo.DeclaringType);
                    }

                    continue;
                }

                if (jsonPropertyInfo.MemberType == MemberTypes.Field && !hasJsonInclude && !Options.IncludeFields)
                {
                    continue;
                }

                if (jsonPropertyInfo.SrcGen_IsExtensionData)
                {
                    if (ExtensionDataProperty != null)
                    {
                        ThrowHelper.ThrowInvalidOperationException_SerializationDuplicateTypeAttribute(Type, typeof(JsonExtensionDataAttribute));
                    }

                    ExtensionDataProperty = jsonPropertyInfo;
                    continue;
                }

                CacheMember(jsonPropertyInfo, propertyCache, ref ignoredMembers);
            }

            PropertyCache = propertyCache;
        }