Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
TypeEnumMetaObject.cs71 linesDownload Raw Back to ComInterop
1// Licensed to the .NET Foundation under one or more agreements.2// The .NET Foundation licenses this file to you under the MIT license.3 4using System;5using System.Collections.Generic;6using System.Dynamic;7using System.Linq.Expressions;8using AstUtils = System.Management.Automation.Interpreter.Utils;9 10namespace System.Management.Automation.ComInterop11{12    internal class TypeEnumMetaObject : DynamicMetaObject13    {14        private readonly ComTypeEnumDesc _desc;15 16        internal TypeEnumMetaObject(ComTypeEnumDesc desc, Expression expression)17            : base(expression, BindingRestrictions.Empty, desc)18        {19            _desc = desc;20        }21 22        public override DynamicMetaObject BindGetMember(GetMemberBinder binder)23        {24            if (_desc.HasMember(binder.Name))25            {26                return new DynamicMetaObject(27                    // return (.bound $arg0).GetValue("<name>")28                    Expression.Constant(((ComTypeEnumDesc)Value).GetValue(binder.Name), typeof(object)),29                    EnumRestrictions()30                );31            }32 33            throw new NotImplementedException();34        }35 36        public override IEnumerable<string> GetDynamicMemberNames()37        {38            return _desc.GetMemberNames();39        }40 41        private BindingRestrictions EnumRestrictions()42        {43            return BindingRestrictions.GetTypeRestriction(44                Expression, typeof(ComTypeEnumDesc)45            ).Merge(46                // ((ComTypeEnumDesc)<arg>).TypeLib.Guid == <guid>47                BindingRestrictions.GetExpressionRestriction(48                    Expression.Equal(49                        Expression.Property(50                            Expression.Property(51                                AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)),52                                typeof(ComTypeDesc).GetProperty(nameof(ComTypeDesc.TypeLib))),53                            typeof(ComTypeLibDesc).GetProperty(nameof(ComTypeLibDesc.Guid))),54                        Expression.Constant(_desc.TypeLib.Guid)55                    )56                )57            ).Merge(58                BindingRestrictions.GetExpressionRestriction(59                    Expression.Equal(60                        Expression.Property(61                            AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)),62                            typeof(ComTypeEnumDesc).GetProperty(nameof(ComTypeEnumDesc.TypeName))63                        ),64                        Expression.Constant(_desc.TypeName)65                    )66                )67            );68        }69    }70}71