예제 #1
0
        /// <summary>
        /// Provides a one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            if (ParameterSetName == ParameterSet.Default)
            {
                //Value is not required, but is required in that we need to explicitly say null
                if (!MyInvocation.BoundParameters.ContainsKey("Value"))
                {
                    throw new ParameterBindingException("Value parameter is mandatory, however a value was not specified. If Value should be empty, specify $null");
                }

                ParseValue();
            }
            else if (ParameterSetName == ParameterSet.Dynamic)
            {
                dynamicParameters = dynamicParams.GetBoundParameters(this, (p, v) => new PropertyParameter(p, PSObjectHelpers.CleanPSObject(v))).ToArray();
            }
            else if (ParameterSetName == ParameterSet.RawProperty)
            {
                RawValue = PSObjectHelpers.CleanPSObject(RawValue);
            }
            else if (ParameterSetName == ParameterSet.Raw)
            {
                parameters = RawParameters.Keys.Cast <object>()
                             .Select(k => new CustomParameter(k.ToString(), PSObjectHelpers.CleanPSObject(RawParameters[k]), ParameterType.MultiParameter))
                             .ToArray();
            }
        }
예제 #2
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            if (this is IDynamicParameters && dynamicParameterSet != null)
            {
                dynamicParameters = dynamicParameterSet.GetBoundParameters(this, (p, v) =>
                {
                    var cleaned = PSObjectUtilities.CleanPSObject(v);

                    if (cleaned == null)
                    {
                        return(new List <SearchFilter>());
                    }

                    var underlying = cleaned.GetType().GetElementType() ?? cleaned.GetType();

                    if (underlying == typeof(object))
                    {
                        if (cleaned.IsIEnumerable())
                        {
                            var first = cleaned.ToIEnumerable().FirstOrDefault();

                            if (first != null)
                            {
                                underlying = first.GetType();
                            }
                        }
                    }

                    if (underlying == typeof(string))
                    {
                        return(GetWildcardFilters(p, cleaned, val => val.ToString()));
                    }
                    if (typeof(IStringEnum).IsAssignableFrom(underlying))
                    {
                        return(GetWildcardFilters(p, cleaned, val => ((IStringEnum)val).StringValue));
                    }

                    return(new[] { GetPipelineFilter(p, cleaned) });
                });
            }

            base.BeginProcessingEx();
        }
예제 #3
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            Value = PSObjectUtilities.CleanPSObject(Value);

            if (DynamicSet())
            {
                dynamicParameters = dynamicParams.GetBoundParameters(this, (p, v) => new ChannelParameter(p, PSObjectUtilities.CleanPSObject(v)));
            }

            base.BeginProcessingEx();
        }