protected override void ProcessRecord() { if (ParameterSetName == "ParamSetVar") { if (m_variables != null) { foreach (PSVariable variable in m_variables) { List <PSEventBindingInfo> bindings = m_manager.GetBindings(variable, IncludeUnboundEvents.IsPresent); if (bindings.Count == 0) { WriteVerbose("No bindings found for PSVariable named " + variable.Name); } else { WriteObject(bindings, true); } } } } else // "ParamSetVarName" { if (m_variableNames != null) { // get bindings for specified variable(s) foreach (string variableName in m_variableNames) { PSVariable variable = m_variableHelper.GetVariableByName(variableName); if (variable != null) { List <PSEventBindingInfo> bindings = m_manager.GetBindings(variable, IncludeUnboundEvents.IsPresent); if (bindings.Count == 0) { WriteVerbose("No bindings found for variable:" + variableName); } else { WriteObject(bindings, true); } } else { string message = String.Format("{0} is null or invalid.", variableName); WriteError(new ErrorRecord(new ArgumentException(message), "InvalidVariableName", ErrorCategory.InvalidArgument, variableName)); } } } else { // get all bindings WriteObject(m_manager.GetBindings(IncludeUnboundEvents.IsPresent), true); } } }
protected override void EndProcessing() { if (ParameterSetName == ParamSetVarName) { Debug.Assert(m_variableName != null, "m_variableName != null"); m_variable = m_variableHelper.GetVariableByName(m_variableName); if ((m_variable == null) || (m_variable.Value == null)) { ThrowTerminatingError( new ErrorRecord(new ArgumentException("Variable is $null or does not exist."), "InvalidVariable", ErrorCategory.InvalidArgument, null)); } } else // ParamSetVar { Debug.Assert(m_variable != null, "m_variable != null"); // ... PSVariable was passed } }