Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
FieldOperations.cs106 linesDownload Raw Back to interpreter
1/* ****************************************************************************2 *3 * Copyright (c) Microsoft Corporation.4 *5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A6 * copy of the license can be found in the License.html file at the root of this distribution. If7 * you cannot locate the Apache License, Version 2.0, please send an email to8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound9 * by the terms of the Apache License, Version 2.0.10 *11 * You must not remove this notice, or any other, from this software.12 *13 *14 * ***************************************************************************/15 16using System.Diagnostics;17using System.Reflection;18 19namespace System.Management.Automation.Interpreter20{21    internal sealed class LoadStaticFieldInstruction : Instruction22    {23        private readonly FieldInfo _field;24 25        public LoadStaticFieldInstruction(FieldInfo field)26        {27            Debug.Assert(field.IsStatic);28            _field = field;29        }30 31        public override int ProducedStack { get { return 1; } }32 33        public override int Run(InterpretedFrame frame)34        {35            frame.Push(_field.GetValue(null));36            return +1;37        }38    }39 40    internal sealed class LoadFieldInstruction : Instruction41    {42        private readonly FieldInfo _field;43 44        public LoadFieldInstruction(FieldInfo field)45        {46            Assert.NotNull(field);47            _field = field;48        }49 50        public override int ConsumedStack { get { return 1; } }51 52        public override int ProducedStack { get { return 1; } }53 54        public override int Run(InterpretedFrame frame)55        {56            frame.Push(_field.GetValue(frame.Pop()));57            return +1;58        }59    }60 61    internal sealed class StoreFieldInstruction : Instruction62    {63        private readonly FieldInfo _field;64 65        public StoreFieldInstruction(FieldInfo field)66        {67            Assert.NotNull(field);68            _field = field;69        }70 71        public override int ConsumedStack { get { return 2; } }72 73        public override int ProducedStack { get { return 0; } }74 75        public override int Run(InterpretedFrame frame)76        {77            object value = frame.Pop();78            object self = frame.Pop();79            _field.SetValue(self, value);80            return +1;81        }82    }83 84    internal sealed class StoreStaticFieldInstruction : Instruction85    {86        private readonly FieldInfo _field;87 88        public StoreStaticFieldInstruction(FieldInfo field)89        {90            Assert.NotNull(field);91            _field = field;92        }93 94        public override int ConsumedStack { get { return 1; } }95 96        public override int ProducedStack { get { return 0; } }97 98        public override int Run(InterpretedFrame frame)99        {100            object value = frame.Pop();101            _field.SetValue(null, value);102            return +1;103        }104    }105}106