Removed redundant visibility check (#36648)
authorYoh Deadfall <yoh.deadfall@hotmail.com>
Mon, 18 May 2020 16:16:23 +0000 (19:16 +0300)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 16:16:23 +0000 (09:16 -0700)
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs

index f0adf74..b97b611 100644 (file)
@@ -111,17 +111,6 @@ namespace System.Text.Json
                                     continue;
                                 }
 
-                                if (IsNonPublicProperty(propertyInfo))
-                                {
-                                    if (JsonPropertyInfo.GetAttribute<JsonIncludeAttribute>(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 @@ namespace System.Text.Json
                                         // else ignore jsonPropertyInfo since it has [JsonIgnore] or it's hidden by a new slot.
                                     }
                                 }
+                                else
+                                {
+                                    if (JsonPropertyInfo.GetAttribute<JsonIncludeAttribute>(propertyInfo) != null)
+                                    {
+                                        ThrowHelper.ThrowInvalidOperationException_JsonIncludeOnNonPublicInvalid(propertyInfo, currentType);
+                                    }
+
+                                    // Non-public properties should not be included for (de)serialization.
+                                }
                             }
                         }
 
@@ -211,13 +209,6 @@ namespace System.Text.Json
             }
         }
 
-        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<string, JsonPropertyInfo> propertyCache, ConstructorInfo constructorInfo)
         {
             ParameterInfo[] parameters = constructorInfo!.GetParameters();