internal static T GetPropertyValue <T>(PSObject pso, string propertyName, RehydrationFlags flags)
        {
            PSPropertyInfo info = pso.Properties[propertyName];

            if ((info == null) && (RehydrationFlags.MissingPropertyOk == (flags & RehydrationFlags.MissingPropertyOk)))
            {
                return(default(T));
            }
            object valueToConvert = info.Value;

            if ((valueToConvert == null) && (RehydrationFlags.NullValueOk == (flags & RehydrationFlags.NullValueOk)))
            {
                return(default(T));
            }
            return((T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), CultureInfo.InvariantCulture));
        }
        private static ListType RehydrateList <ListType, ItemType>(PSObject pso, string propertyName, RehydrationFlags flags) where ListType : IList, new()
        {
            ArrayList list = GetPropertyValue <ArrayList>(pso, propertyName, flags);

            if (list == null)
            {
                if (RehydrationFlags.NullValueMeansEmptyList != (flags & RehydrationFlags.NullValueMeansEmptyList))
                {
                    return(default(ListType));
                }
                if (default(ListType) != null)
                {
                    return(default(ListType));
                }
                return(Activator.CreateInstance <ListType>());
            }
            ListType local = (default(ListType) == null) ? Activator.CreateInstance <ListType>() : default(ListType);

            foreach (object obj2 in list)
            {
                ItemType local2 = (ItemType)LanguagePrimitives.ConvertTo(obj2, typeof(ItemType), CultureInfo.InvariantCulture);
                local.Add(local2);
            }
            return(local);
        }