From 6ee608ff58ac990439c4bf9f2f3f5b726ca36092 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Sun, 7 Jan 2018 15:53:07 -0800 Subject: [PATCH] [Feature] Consider a policy is undefined if none of its properties are set --- src/System.Management.Automation/engine/Utils.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 04b13ee032..800036e65c 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -595,6 +595,7 @@ namespace System.Management.Automation // and populate its properties with the settings object tInstance = Activator.CreateInstance(tType, nonPublic: true); var properties = tType.GetProperties(BindingFlags.Instance | BindingFlags.Public); + bool isAnyPropertySet = false; string[] valueNames = gpoKey.GetValueNames(); string[] subKeyNames = gpoKey.GetSubKeyNames(); @@ -660,11 +661,13 @@ namespace System.Management.Automation if (propertyValue != null) { property.SetValue(tInstance, propertyValue); + isAnyPropertySet = true; } } } - return (T) tInstance; + // If no property is set, then we consider this policy as undefined + return isAnyPropertySet ? (T) tInstance : null; } }