Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions.JTokenExtensions.ToPsObject C# (CSharp) Method

ToPsObject() static private method

Converts a JObject to a PSObject
static private ToPsObject ( this jtoken, string objectType = null ) : System.Management.Automation.PSObject
jtoken this The
objectType string The type of the object.
return System.Management.Automation.PSObject
        internal static PSObject ToPsObject(this JToken jtoken, string objectType = null)
        {
            if (jtoken == null)
            {
                return null;
            }

            if (jtoken.Type != JTokenType.Object)
            {
                return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken));
            }

            var jobject = (JObject)jtoken;
            var psObject = new PSObject();

            if (!string.IsNullOrWhiteSpace(objectType))
            {
                psObject.TypeNames.Add(objectType);
            }

            foreach (var property in jobject.Properties())
            {
                psObject.Properties.Add(new PSNoteProperty(
                    name: property.Name,
                    value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: property.Value)));
            }

            return psObject;
        }