From ae78e3d0adf025a86611e0f8dfe2f847252ee4c9 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Mon, 18 May 2020 14:28:39 +0300 Subject: [PATCH] Removed redundant visibility check --- .../Text/Json/Serialization/JsonClassInfo.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs index f0adf7412981ff..b97b6117923d46 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs @@ -111,17 +111,6 @@ public JsonClassInfo(Type type, JsonSerializerOptions options) continue; } - if (IsNonPublicProperty(propertyInfo)) - { - if (JsonPropertyInfo.GetAttribute(propertyInfo) != null) - { - ThrowHelper.ThrowInvalidOperationException_JsonIncludeOnNonPublicInvalid(propertyInfo, currentType); - } - - // Non-public properties should not be included for (de)serialization. - continue; - } - // For now we only support public getters\setters if (propertyInfo.GetMethod?.IsPublic == true || propertyInfo.SetMethod?.IsPublic == true) @@ -149,6 +138,15 @@ public JsonClassInfo(Type type, JsonSerializerOptions options) // else ignore jsonPropertyInfo since it has [JsonIgnore] or it's hidden by a new slot. } } + else + { + if (JsonPropertyInfo.GetAttribute(propertyInfo) != null) + { + ThrowHelper.ThrowInvalidOperationException_JsonIncludeOnNonPublicInvalid(propertyInfo, currentType); + } + + // Non-public properties should not be included for (de)serialization. + } } } @@ -211,13 +209,6 @@ public JsonClassInfo(Type type, JsonSerializerOptions options) } } - private static bool IsNonPublicProperty(PropertyInfo propertyInfo) - { - MethodInfo? getMethod = propertyInfo.GetMethod; - MethodInfo? setMethod = propertyInfo.SetMethod; - return !((getMethod != null && getMethod.IsPublic) || (setMethod != null && setMethod.IsPublic)); - } - private void InitializeConstructorParameters(Dictionary propertyCache, ConstructorInfo constructorInfo) { ParameterInfo[] parameters = constructorInfo!.GetParameters();