Esempio n. 1
0
 private string BuildMessage(Cmdlet cmdlet, string baseName, string resourceId, params object[] args)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     if (string.IsNullOrEmpty(baseName))
     {
         throw PSTraceSource.NewArgumentNullException("baseName");
     }
     if (string.IsNullOrEmpty(resourceId))
     {
         throw PSTraceSource.NewArgumentNullException("resourceId");
     }
     string template = "";
     try
     {
         template = cmdlet.GetResourceString(baseName, resourceId);
     }
     catch (MissingManifestResourceException exception)
     {
         this._textLookupError = exception;
         return "";
     }
     catch (ArgumentException exception2)
     {
         this._textLookupError = exception2;
         return "";
     }
     return this.BuildMessage(template, baseName, resourceId, args);
 }
        /// <summary>
        /// If HelpMessageBaseName and HelpMessageResourceId are set, the help info is
        /// loaded from the resource indicated by HelpMessageBaseName and HelpMessageResourceId.
        /// If that fails and HelpMessage is set, the help info is set to HelpMessage; otherwise,
        /// the exception that is thrown when loading the resource is thrown.
        /// If both HelpMessageBaseName and HelpMessageResourceId are not set, the help info is
        /// set to HelpMessage.
        /// </summary>
        /// <returns>
        /// Help info about the parameter
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// If the value of the specified resource is not a string and
        ///     HelpMessage is not set.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If only one of HelpMessageBaseName and HelpMessageResourceId is set
        ///     OR if no usable resources have been found, and
        ///     there are no neutral culture resources and HelpMessage is not set.
        /// </exception>
        internal string GetHelpMessage(Cmdlet cmdlet)
        {
            string helpInfo             = null;
            bool   isHelpMsgSet         = !string.IsNullOrEmpty(HelpMessage);
            bool   isHelpMsgBaseNameSet = !string.IsNullOrEmpty(HelpMessageBaseName);
            bool   isHelpMsgResIdSet    = !string.IsNullOrEmpty(HelpMessageResourceId);

            if (isHelpMsgBaseNameSet ^ isHelpMsgResIdSet)
            {
                throw PSTraceSource.NewArgumentException(isHelpMsgBaseNameSet ? "HelpMessageResourceId" : "HelpMessageBaseName");
            }

            if (isHelpMsgBaseNameSet && isHelpMsgResIdSet)
            {
                try
                {
                    helpInfo = cmdlet.GetResourceString(HelpMessageBaseName, HelpMessageResourceId);
                }
                catch (ArgumentException)
                {
                    if (isHelpMsgSet)
                    {
                        helpInfo = HelpMessage;
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (InvalidOperationException)
                {
                    if (isHelpMsgSet)
                    {
                        helpInfo = HelpMessage;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else if (isHelpMsgSet)
            {
                helpInfo = HelpMessage;
            }

            return(helpInfo);
        }
 internal string GetHelpMessage(Cmdlet cmdlet)
 {
     string helpMessage = null;
     bool flag = !string.IsNullOrEmpty(this.HelpMessage);
     bool flag2 = !string.IsNullOrEmpty(this.HelpMessageBaseName);
     bool flag3 = !string.IsNullOrEmpty(this.HelpMessageResourceId);
     if (flag2 ^ flag3)
     {
         throw PSTraceSource.NewArgumentException(flag2 ? "HelpMessageResourceId" : "HelpMessageBaseName");
     }
     if (flag2 && flag3)
     {
         try
         {
             return cmdlet.GetResourceString(this.HelpMessageBaseName, this.HelpMessageResourceId);
         }
         catch (ArgumentException)
         {
             if (!flag)
             {
                 throw;
             }
             return this.HelpMessage;
         }
         catch (InvalidOperationException)
         {
             if (!flag)
             {
                 throw;
             }
             return this.HelpMessage;
         }
     }
     if (flag)
     {
         helpMessage = this.HelpMessage;
     }
     return helpMessage;
 }
Esempio n. 4
0
        private string BuildMessage(
            Cmdlet cmdlet,
            string baseName,
            string resourceId,
            params object[] args)
        {
            if (null == cmdlet)
                throw PSTraceSource.NewArgumentNullException("cmdlet");

            if (String.IsNullOrEmpty(baseName))
                throw PSTraceSource.NewArgumentNullException("baseName");

            if (String.IsNullOrEmpty(resourceId))
                throw PSTraceSource.NewArgumentNullException("resourceId");

            string template = "";

            try
            {
                template = cmdlet.GetResourceString(baseName, resourceId);
            }
            catch (MissingManifestResourceException e)
            {
                _textLookupError = e;
                return ""; // fallback to Exception.Message
            }
            catch (ArgumentException e)
            {
                _textLookupError = e;
                return ""; // fallback to Exception.Message
            }
            return BuildMessage(template, baseName, resourceId, args);
        } // BuildMessage
        /// <summary>
        /// If HelpMessageBaseName and HelpMessageResourceId are set, the help info is
        /// loaded from the resource indicated by HelpMessageBaseName and HelpMessageResourceId.
        /// If that fails and HelpMessage is set, the help info is set to HelpMessage; otherwise,
        /// the exception that is thrown when loading the resource is thrown.
        /// If both HelpMessageBaseName and HelpMessageResourceId are not set, the help info is
        /// set to HelpMessage
        /// </summary>
        /// 
        /// <returns>
        /// Help info about the parameter
        /// </returns>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the value of the specified resource is not a string and
        ///     HelpMessage is not set.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// If only one of HelpMessageBaseName and HelpMessageResourceId is set
        ///     OR if no usable resources have been found, and
        ///     there are no neutral culture resources and HelpMessage is not set.
        /// </exception>
        /// 
        internal string GetHelpMessage(Cmdlet cmdlet)
        {
            string helpInfo = null;
            bool isHelpMsgSet = !string.IsNullOrEmpty(HelpMessage);
            bool isHelpMsgBaseNameSet = !string.IsNullOrEmpty(HelpMessageBaseName);
            bool isHelpMsgResIdSet = !string.IsNullOrEmpty(HelpMessageResourceId);

            if (isHelpMsgBaseNameSet ^ isHelpMsgResIdSet)
            {
                throw PSTraceSource.NewArgumentException(isHelpMsgBaseNameSet ? "HelpMessageResourceId" : "HelpMessageBaseName");
            }

            if (isHelpMsgBaseNameSet && isHelpMsgResIdSet)
            {
                try
                {
                    helpInfo = cmdlet.GetResourceString(HelpMessageBaseName, HelpMessageResourceId);
                }
                catch (ArgumentException)
                {
                    if (isHelpMsgSet)
                    {
                        helpInfo = HelpMessage;
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (InvalidOperationException)
                {
                    if (isHelpMsgSet)
                    {
                        helpInfo = HelpMessage;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else if (isHelpMsgSet)
            {
                helpInfo = HelpMessage;
            }
            return helpInfo;
        }