Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
ObjectRef.cs92 linesDownload Raw Back to common
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using Dbg = System.Management.Automation.Diagnostics;5 6namespace System.Management.Automation.Remoting7{8    /// <summary>9    /// The purpose of this class is to hide an object (mask it) and replace it10    /// with a substitute temporarily. This is used in pushing and popping11    /// runspaces. It is also used to temporarily set a PowerShell object's host as12    /// the Runspace object's host when the PowerShell object is executed.13    /// </summary>14    internal class ObjectRef<T> where T : class15    {16        /// <summary>17        /// New value.18        /// </summary>19        private T _newValue;20        /// <summary>21        /// Old value.22        /// </summary>23        private readonly T _oldValue;24 25        /// <summary>26        /// Old value.27        /// </summary>28        internal T OldValue29        {30            get31            {32                return _oldValue;33            }34        }35 36        /// <summary>37        /// Value.38        /// </summary>39        internal T Value40        {41            get42            {43                if (_newValue == null)44                {45                    return _oldValue;46                }47                else48                {49                    return _newValue;50                }51            }52        }53 54        /// <summary>55        /// Is overridden.56        /// </summary>57        internal bool IsOverridden58        {59            get60            {61                return _newValue != null;62            }63        }64 65        /// <summary>66        /// Constructor for ObjectRef.67        /// </summary>68        internal ObjectRef(T oldValue)69        {70            Dbg.Assert(oldValue != null, "Expected oldValue != null");71            _oldValue = oldValue;72        }73 74        /// <summary>75        /// Override.76        /// </summary>77        internal void Override(T newValue)78        {79            Dbg.Assert(newValue != null, "Expected newValue != null");80            _newValue = newValue;81        }82 83        /// <summary>84        /// Revert.85        /// </summary>86        internal void Revert()87        {88            _newValue = null;89        }90    }91}92