Ejemplo n.º 1
0
        public virtual void Initialize(
            Type parentClassType,
            Type declaredPropertyType,
            Type runtimePropertyType,
            Type implementedPropertyType,
            PropertyInfo propertyInfo,
            Type elementType,
            JsonConverter converter,
            JsonSerializerOptions options)
        {
            ParentClassType         = parentClassType;
            DeclaredPropertyType    = declaredPropertyType;
            RuntimePropertyType     = runtimePropertyType;
            ImplementedPropertyType = implementedPropertyType;
            PropertyInfo            = propertyInfo;
            ElementType             = elementType;
            Options        = options;
            IsNullableType = runtimePropertyType.IsGenericType && runtimePropertyType.GetGenericTypeDefinition() == typeof(Nullable <>);
            CanBeNull      = IsNullableType || !runtimePropertyType.IsValueType;

            if (converter != null)
            {
                ConverterBase = converter;

                HasInternalConverter = (converter.GetType().Assembly == GetType().Assembly);

                // Avoid calling GetClassType since it will re-ask if there is a converter which is slow.
                if (runtimePropertyType == typeof(object))
                {
                    ClassType = ClassType.Unknown;
                }
                else
                {
                    ClassType = ClassType.Value;
                }
            }
            // Special case for immutable collections.
            else if (declaredPropertyType != implementedPropertyType && !JsonClassInfo.IsNativelySupportedCollection(declaredPropertyType))
            {
                ClassType = JsonClassInfo.GetClassType(declaredPropertyType, options);
            }
            else
            {
                ClassType = JsonClassInfo.GetClassType(runtimePropertyType, options);
            }
        }