Ejemplo n.º 1
0
        internal static ReflectParameterDescriptor GetParameterDescriptor(
            [NotNull][ItemNotNull] IReadOnlyList <MemberInfo> members)
        {
            if (!_descriptorCache.TryGetValue(members, out var descriptor))
            {
                var initializationInfo = new ReflectParameterDescriptorInitializationInfo(members);
                _descriptorCache[members] = descriptor = new ReflectParameterDescriptor(initializationInfo);
            }

            return(descriptor);
        }
Ejemplo n.º 2
0
        private IEnumerable <ReflectParameterDescriptor> ProcessNonDynamicCompoundParameter(
            [NotNull] MemberInfo compoundMember,
            [NotNull] Type compoundParameterType)
        {
            var parameterMembers = Utilities.GetParameterMembers(compoundParameterType);

            foreach (var parameterMember in parameterMembers)
            {
                if (!Attribute.IsDefined(parameterMember, typeof(ParameterAttribute), true))
                {
                    continue;
                }

                var descriptor = ReflectParameterDescriptor.GetParameterDescriptor(
                    new[] { compoundMember, parameterMember });

                yield return(descriptor);
            }
        }
Ejemplo n.º 3
0
        public DynamicParameterInstance EnableParameter(
            [NotNull][ItemNotNull] IReadOnlyList <MemberInfo> members)
        {
            if (members is null)
            {
                throw new ArgumentNullException(nameof(members));
            }

            var allMembers = new List <MemberInfo>
            {
                this.CurrentParameter
            };

            allMembers.AddRange(members);

            var descriptor = ReflectParameterDescriptor.GetParameterDescriptor(allMembers);

            var instance = this._parentContext.EnableParameter(descriptor);

            return(instance);
        }
Ejemplo n.º 4
0
        public static DynamicParameterInstance EnableDynamicParameter <TCmdlet, TParameter>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] Expression <Func <TCmdlet, TParameter> > parameterExpression)
            where TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (parameterExpression is null)
            {
                throw new ArgumentNullException(nameof(parameterExpression));
            }

            var members    = Utilities.ParseExpression((MemberExpression)parameterExpression.Body);
            var descriptor = ReflectParameterDescriptor.GetParameterDescriptor(members);

            var instance = EnableDynamicParameter(cmdlet, descriptor);

            return(instance);
        }