/// <summary>
        /// Append to a dictionary any properties that might have been added to an object (via PSObject) through the Add-Member cmdlet.
        /// If the passed in object is a custom object (not a simple object, not a dictionary, not a list, get processed in ProcessCustomObject method),
        /// we also take Adapted properties into account. Otherwise, we only consider the Extended properties.
        /// When the object is a pure PSObject, it also gets processed in "ProcessCustomObject" before reaching this method, so we will
        /// iterate both extended and adapted properties for it. Since it's a pure PSObject, there will be no adapted properties.
        /// </summary>
        /// <param name="psobj">The containing PSObject, or null if the base object was not contained in a PSObject</param>
        /// <param name="receiver">The dictionary to which any additional properties will be appended</param>
        /// <param name="depth">The current depth into the object graph</param>
        /// <param name="isCustomObject">The processed object is a custom object</param>
        private void AppendPsProperties(PSObject psobj, IDictionary receiver, int depth, bool isCustomObject)
        {
            // serialize only Extended and Adapted properties..
            PSMemberInfoCollection <PSPropertyInfo> srcPropertiesToSearch =
                new PSMemberInfoIntegratingCollection <PSPropertyInfo>(psobj,
                                                                       isCustomObject ? PSObject.GetPropertyCollection(PSMemberViewTypes.Extended | PSMemberViewTypes.Adapted) :
                                                                       PSObject.GetPropertyCollection(PSMemberViewTypes.Extended));

            foreach (PSPropertyInfo prop in srcPropertiesToSearch)
            {
                object value = null;
                try
                {
                    value = prop.Value;
                }
                catch (Exception ex)
                {
                    UtilityCommon.CheckForSevereException(this, ex);
                }

                if (!receiver.Contains(prop.Name))
                {
                    receiver[prop.Name] = ProcessValue(value, depth + 1);
                }
            }
        }
Ejemplo n.º 2
0
 public override void Write(string output)
 {
     try
     {
         this.cachedWrite.Append(output);
     }
     catch (Exception exception)
     {
         UtilityCommon.CheckForSevereException(null, exception);
     }
 }
Ejemplo n.º 3
0
 public override void Write(string output)
 {
     try
     {
         _cachedWrite.Append(output);
     }
     catch (Exception e)
     {
         UtilityCommon.CheckForSevereException(null, e);
         // Catch and ignore all exceptions while tracing
         // We don't want tracing to bring down the process.
     }
 }
Ejemplo n.º 4
0
 public override void WriteLine(string output)
 {
     try
     {
         this.cachedWrite.Append(output);
         this.ui.WriteDebugLine(this.cachedWrite.ToString());
         this.cachedWrite.Remove(0, this.cachedWrite.Length);
     }
     catch (Exception exception)
     {
         UtilityCommon.CheckForSevereException(null, exception);
     }
 }
Ejemplo n.º 5
0
        public override void WriteLine(string output)
        {
            try
            {
                _cachedWrite.Append(output);

                _ui.WriteDebugLine(_cachedWrite.ToString());
                _cachedWrite.Remove(0, _cachedWrite.Length);
            }
            catch (Exception e)
            {
                UtilityCommon.CheckForSevereException(null, e);
                // Catch and ignore all exceptions while tracing
                // We don't want tracing to bring down the process.
            }
        }
Ejemplo n.º 6
0
        internal string GetToStringValueForProperty(PSPropertyInfo property)
        {
            string str = null;

            try
            {
                object obj2 = property.Value;
                if (obj2 != null)
                {
                    str = obj2.ToString();
                }
            }
            catch (Exception exception)
            {
                UtilityCommon.CheckForSevereException(this._cmdlet, exception);
            }
            return(str);
        }
Ejemplo n.º 7
0
        private void AppendPsProperties(PSObject psobj, IDictionary receiver, int depth, bool isCustomObject)
        {
            PSMemberInfoCollection <PSPropertyInfo> infos = new PSMemberInfoIntegratingCollection <PSPropertyInfo>(psobj, isCustomObject ? PSObject.GetPropertyCollection(PSMemberViewTypes.Adapted | PSMemberViewTypes.Extended) : PSObject.GetPropertyCollection(PSMemberViewTypes.Extended));

            foreach (PSPropertyInfo info in infos)
            {
                object obj2 = null;
                try
                {
                    obj2 = info.Value;
                }
                catch (Exception exception)
                {
                    UtilityCommon.CheckForSevereException(this, exception);
                }
                if (!receiver.Contains(info.Name))
                {
                    receiver[info.Name] = this.ProcessValue(obj2, depth + 1);
                }
            }
        }