示例#1
0
        internal Collection <MergedCompiledCommandParameter> AddMetadataForBinder(
            InternalParameterMetadata parameterMetadata,
            ParameterBinderAssociation binderAssociation)
        {
            if (parameterMetadata == null)
            {
                throw MergedCommandParameterMetadata.tracer.NewArgumentNullException(nameof(parameterMetadata));
            }
            Collection <MergedCompiledCommandParameter> collection = new Collection <MergedCompiledCommandParameter>();

            foreach (KeyValuePair <string, CompiledCommandParameter> bindableParameter in parameterMetadata.BindableParameters)
            {
                if (this.bindableParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException metadataException = new MetadataException("ParameterNameAlreadyExistsForCommand", (Exception)null, "Metadata", "ParameterNameAlreadyExistsForCommand", new object[1]
                    {
                        (object)bindableParameter.Key
                    });
                    MergedCommandParameterMetadata.tracer.TraceException((Exception)metadataException);
                    throw metadataException;
                }
                if (this.aliasedParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException metadataException = new MetadataException("ParameterNameConflictsWithAlias", (Exception)null, "Metadata", "ParameterNameConflictsWithAlias", new object[2]
                    {
                        (object)bindableParameter.Key,
                        (object)this.RetrieveParameterNameForAlias(bindableParameter.Key, this.aliasedParameters)
                    });
                    MergedCommandParameterMetadata.tracer.TraceException((Exception)metadataException);
                    throw metadataException;
                }
                MergedCompiledCommandParameter commandParameter = new MergedCompiledCommandParameter(bindableParameter.Value, binderAssociation);
                this.bindableParameters.Add(bindableParameter.Key, commandParameter);
                collection.Add(commandParameter);
                foreach (string alias in bindableParameter.Value.Aliases)
                {
                    if (this.aliasedParameters.ContainsKey(alias))
                    {
                        MetadataException metadataException = new MetadataException("AliasParameterNameAlreadyExistsForCommand", (Exception)null, "Metadata", "AliasParameterNameAlreadyExistsForCommand", new object[1]
                        {
                            (object)alias
                        });
                        MergedCommandParameterMetadata.tracer.TraceException((Exception)metadataException);
                        throw metadataException;
                    }
                    if (this.bindableParameters.ContainsKey(alias))
                    {
                        MetadataException metadataException = new MetadataException("ParameterNameConflictsWithAlias", (Exception)null, "Metadata", "ParameterNameConflictsWithAlias", new object[2]
                        {
                            (object)this.RetrieveParameterNameForAlias(alias, this.bindableParameters),
                            (object)bindableParameter.Value.Name
                        });
                        MergedCommandParameterMetadata.tracer.TraceException((Exception)metadataException);
                        throw metadataException;
                    }
                    this.aliasedParameters.Add(alias, commandParameter);
                }
            }
            return(collection);
        }
示例#2
0
        /// <summary>
        /// Extracts the data from the ParameterAttribute and creates the member data as necessary.
        /// </summary>
        /// <param name="parameterName">
        /// The name of the parameter.
        /// </param>
        /// <param name="parameter">
        /// The instance of the ParameterAttribute to extract the data from.
        /// </param>
        /// <exception cref="MetadataException">
        /// If a parameter set name has already been declared on this parameter.
        /// </exception>
        private void ProcessParameterAttribute(
            string parameterName,
            ParameterAttribute parameter)
        {
            // If the parameter set name already exists on this parameter and the set name is the default parameter
            // set name, it is an error.

            if (ParameterSetData.ContainsKey(parameter.ParameterSetName))
            {
                MetadataException e =
                    new MetadataException(
                        "ParameterDeclaredInParameterSetMultipleTimes",
                        null,
                        DiscoveryExceptions.ParameterDeclaredInParameterSetMultipleTimes,
                        parameterName,
                        parameter.ParameterSetName);

                throw e;
            }

            if (parameter.ValueFromPipeline || parameter.ValueFromPipelineByPropertyName)
            {
                IsPipelineParameterInSomeParameterSet = true;
            }

            if (parameter.Mandatory)
            {
                IsMandatoryInSomeParameterSet = true;
            }

            // Construct an instance of the parameter set specific data
            ParameterSetSpecificMetadata parameterSetSpecificData = new ParameterSetSpecificMetadata(parameter);

            ParameterSetData.Add(parameter.ParameterSetName, parameterSetSpecificData);
        }
        /// <summary>
        /// Merges the specified metadata with the other metadata already defined
        /// in this object.
        /// </summary>
        /// <param name="parameterMetadata">
        /// The compiled metadata for the type to be merged.
        /// </param>
        /// <param name="binderAssociation">
        /// The type of binder that the CommandProcessor will use to bind
        /// the parameters for <paramref name="parameterMetadata"/>
        /// </param>
        /// <returns>
        /// A collection of the merged parameter metadata that was added.
        /// </returns>
        /// <exception cref="MetadataException">
        /// If a parameter name or alias described in the <paramref name="parameterMetadata"/> already
        /// exists.
        /// </exception>
        internal Collection <MergedCompiledCommandParameter> AddMetadataForBinder(
            InternalParameterMetadata parameterMetadata,
            ParameterBinderAssociation binderAssociation)
        {
            if (parameterMetadata == null)
            {
                throw PSTraceSource.NewArgumentNullException("parameterMetadata");
            }

            Collection <MergedCompiledCommandParameter> result =
                new Collection <MergedCompiledCommandParameter>();

            // Merge in the bindable parameters

            foreach (KeyValuePair <string, CompiledCommandParameter> bindableParameter in parameterMetadata.BindableParameters)
            {
                if (_bindableParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException exception =
                        new MetadataException(
                            "ParameterNameAlreadyExistsForCommand",
                            null,
                            Metadata.ParameterNameAlreadyExistsForCommand,
                            bindableParameter.Key);
                    throw exception;
                }

                // NTRAID#Windows Out Of Band Releases-926371-2005/12/27-JonN
                if (_aliasedParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException exception =
                        new MetadataException(
                            "ParameterNameConflictsWithAlias",
                            null,
                            Metadata.ParameterNameConflictsWithAlias,
                            bindableParameter.Key,
                            RetrieveParameterNameForAlias(bindableParameter.Key, _aliasedParameters));
                    throw exception;
                }

                MergedCompiledCommandParameter mergedParameter =
                    new MergedCompiledCommandParameter(bindableParameter.Value, binderAssociation);

                _bindableParameters.Add(bindableParameter.Key, mergedParameter);
                result.Add(mergedParameter);

                // Merge in the aliases

                foreach (string aliasName in bindableParameter.Value.Aliases)
                {
                    if (_aliasedParameters.ContainsKey(aliasName))
                    {
                        MetadataException exception =
                            new MetadataException(
                                "AliasParameterNameAlreadyExistsForCommand",
                                null,
                                Metadata.AliasParameterNameAlreadyExistsForCommand,
                                aliasName);
                        throw exception;
                    }

                    // NTRAID#Windows Out Of Band Releases-926371-2005/12/27-JonN
                    if (_bindableParameters.ContainsKey(aliasName))
                    {
                        MetadataException exception =
                            new MetadataException(
                                "ParameterNameConflictsWithAlias",
                                null,
                                Metadata.ParameterNameConflictsWithAlias,
                                RetrieveParameterNameForAlias(aliasName, _bindableParameters),
                                bindableParameter.Value.Name);
                        throw exception;
                    }

                    _aliasedParameters.Add(aliasName, mergedParameter);
                }
            }

            return(result);
        }
        } // ReplaceMetadata

        /// <summary>
        /// Merges the specified metadata with the other metadata already defined
        /// in this object.
        /// </summary>
        /// 
        /// <param name="parameterMetadata">
        /// The compiled metadata for the type to be merged.
        /// </param>
        /// 
        /// <param name="binderAssociation">
        /// The type of binder that the CommandProcessor will use to bind
        /// the parameters for <paramref name="parameterMetadata"/>
        /// </param>
        /// 
        /// <returns>
        /// A collection of the merged parameter metadata that was added.
        /// </returns>
        /// 
        /// <exception cref="MetadataException">
        /// If a parameter name or alias described in the <paramref name="parameterMetadata"/> already
        /// exists.
        /// </exception>
        /// 
        internal Collection<MergedCompiledCommandParameter> AddMetadataForBinder(
            InternalParameterMetadata parameterMetadata,
            ParameterBinderAssociation binderAssociation)
        {
            if (parameterMetadata == null)
            {
                throw PSTraceSource.NewArgumentNullException("parameterMetadata");
            }

            Collection<MergedCompiledCommandParameter> result =
                new Collection<MergedCompiledCommandParameter>();

            // Merge in the bindable parameters

            foreach (KeyValuePair<string, CompiledCommandParameter> bindableParameter in parameterMetadata.BindableParameters)
            {
                if (_bindableParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException exception =
                        new MetadataException(
                            "ParameterNameAlreadyExistsForCommand",
                            null,
                            Metadata.ParameterNameAlreadyExistsForCommand,
                            bindableParameter.Key);
                    throw exception;
                }

                // NTRAID#Windows Out Of Band Releases-926371-2005/12/27-JonN
                if (_aliasedParameters.ContainsKey(bindableParameter.Key))
                {
                    MetadataException exception =
                        new MetadataException(
                            "ParameterNameConflictsWithAlias",
                            null,
                            Metadata.ParameterNameConflictsWithAlias,
                            bindableParameter.Key,
                            RetrieveParameterNameForAlias(bindableParameter.Key, _aliasedParameters));
                    throw exception;
                }

                MergedCompiledCommandParameter mergedParameter =
                    new MergedCompiledCommandParameter(bindableParameter.Value, binderAssociation);

                _bindableParameters.Add(bindableParameter.Key, mergedParameter);
                result.Add(mergedParameter);

                // Merge in the aliases

                foreach (string aliasName in bindableParameter.Value.Aliases)
                {
                    if (_aliasedParameters.ContainsKey(aliasName))
                    {
                        MetadataException exception =
                            new MetadataException(
                                "AliasParameterNameAlreadyExistsForCommand",
                                null,
                                Metadata.AliasParameterNameAlreadyExistsForCommand,
                                aliasName);
                        throw exception;
                    }

                    // NTRAID#Windows Out Of Band Releases-926371-2005/12/27-JonN
                    if (_bindableParameters.ContainsKey(aliasName))
                    {
                        MetadataException exception =
                            new MetadataException(
                                "ParameterNameConflictsWithAlias",
                                null,
                                Metadata.ParameterNameConflictsWithAlias,
                                RetrieveParameterNameForAlias(aliasName, _bindableParameters),
                                bindableParameter.Value.Name);
                        throw exception;
                    }

                    _aliasedParameters.Add(aliasName, mergedParameter);
                }
            }
            return result;
        }