Пример #1
0
        /// <summary>
        /// Identifies/detects a switch that takes parameters.
        /// </summary>
        /// <param name="switchName"></param>
        /// <param name="parameterizedSwitch">[out] switch identifier (from ParameterizedSwitch enumeration)</param>
        /// <param name="duplicateSwitchErrorMessage"></param>
        /// <param name="multipleParametersAllowed"></param>
        /// <param name="missingParametersErrorMessage"></param>
        /// <param name="unquoteParameters"></param>
        /// <returns>true, if switch is a recognized switch that takes parameters</returns>
        internal static bool IsParameterizedSwitch
        (
            string switchName,
            out ParameterizedSwitch parameterizedSwitch,
            out string duplicateSwitchErrorMessage,
            out bool multipleParametersAllowed,
            out string missingParametersErrorMessage,
            out bool unquoteParameters
        )
        {
            parameterizedSwitch           = ParameterizedSwitch.Invalid;
            duplicateSwitchErrorMessage   = null;
            multipleParametersAllowed     = false;
            missingParametersErrorMessage = null;
            unquoteParameters             = false;

            foreach (ParameterizedSwitchInfo switchInfo in s_parameterizedSwitchesMap)
            {
                foreach (string parameterizedSwitchName in switchInfo.switchNames)
                {
                    if (String.Compare(switchName, parameterizedSwitchName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        parameterizedSwitch           = switchInfo.parameterizedSwitch;
                        duplicateSwitchErrorMessage   = switchInfo.duplicateSwitchErrorMessage;
                        multipleParametersAllowed     = switchInfo.multipleParametersAllowed;
                        missingParametersErrorMessage = switchInfo.missingParametersErrorMessage;
                        unquoteParameters             = switchInfo.unquoteParameters;
                        break;
                    }
                }
            }

            return(parameterizedSwitch != ParameterizedSwitch.Invalid);
        }
Пример #2
0
        internal bool SetParameterizedSwitch(ParameterizedSwitch parameterizedSwitch, string commandLineArg, string switchParameters, bool multipleParametersAllowed, bool unquoteParameters)
        {
            bool flag = false;

            if (this.parameterizedSwitches[(int)parameterizedSwitch].commandLineArg == null)
            {
                this.parameterizedSwitches[(int)parameterizedSwitch].parameters = new ArrayList();
            }
            this.parameterizedSwitches[(int)parameterizedSwitch].commandLineArg = commandLineArg;
            if (multipleParametersAllowed)
            {
                int num;
                this.parameterizedSwitches[(int)parameterizedSwitch].parameters.AddRange(QuotingUtilities.SplitUnquoted(switchParameters, 0x7fffffff, false, unquoteParameters, out num, parameterSeparators));
                return(num == 0);
            }
            if (unquoteParameters)
            {
                switchParameters = QuotingUtilities.Unquote(switchParameters);
            }
            if (switchParameters.Length > 0)
            {
                this.parameterizedSwitches[(int)parameterizedSwitch].parameters.Add(switchParameters);
                flag = true;
            }
            return(flag);
        }
Пример #3
0
        /// <summary>
        /// Called when a recognized switch that takes parameters is detected on the command line.
        /// </summary>
        /// <param name="parameterizedSwitch"></param>
        /// <param name="switchParameters"></param>
        /// <param name="multipleParametersAllowed"></param>
        /// <param name="unquoteParameters"></param>
        /// <returns>true, if the given parameters were successfully stored</returns>
        internal bool SetParameterizedSwitch
        (
            ParameterizedSwitch parameterizedSwitch,
            string commandLineArg,
            string switchParameters,
            bool multipleParametersAllowed,
            bool unquoteParameters
        )
        {
            bool parametersStored = false;

            // if this is the first time this switch has been detected
            if (_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg == null)
            {
                // initialize its parameter storage
                _parameterizedSwitches[(int)parameterizedSwitch].parameters = new ArrayList();

                // save the switch text
                _parameterizedSwitches[(int)parameterizedSwitch].commandLineArg = commandLineArg;
            }
            else
            {
                // append the switch text
                _parameterizedSwitches[(int)parameterizedSwitch].commandLineArg = string.Concat(
                        _parameterizedSwitches[(int)parameterizedSwitch].commandLineArg,
                        " ",
                        commandLineArg
                    );
            }

            // check if the switch has multiple parameters
            if (multipleParametersAllowed)
            {
                // store all the switch parameters
                int emptyParameters;
                _parameterizedSwitches[(int)parameterizedSwitch].parameters.AddRange(QuotingUtilities.SplitUnquoted(switchParameters, int.MaxValue, false /* discard empty parameters */, unquoteParameters, out emptyParameters, s_parameterSeparators));

                // check if they were all stored successfully i.e. they were all non-empty (after removing quoting, if requested)
                parametersStored = (emptyParameters == 0);
            }
            else
            {
                if (unquoteParameters)
                {
                    // NOTE: removing quoting from the parameters can reduce the parameters to an empty string
                    switchParameters = QuotingUtilities.Unquote(switchParameters);
                }

                // if the switch actually has parameters, store them
                if (switchParameters.Length > 0)
                {
                    _parameterizedSwitches[(int)parameterizedSwitch].parameters.Add(switchParameters);

                    parametersStored = true;
                }
            }

            return parametersStored;
        }
Пример #4
0
 internal string[] this[ParameterizedSwitch parameterizedSwitch]
 {
     get
     {
         if (this.parameterizedSwitches[(int)parameterizedSwitch].commandLineArg == null)
         {
             return(noParameters);
         }
         return((string[])this.parameterizedSwitches[(int)parameterizedSwitch].parameters.ToArray(typeof(string)));
     }
 }
Пример #5
0
 /// <summary>
 /// Gets the parameters (if any) detected on the command line for the given parameterized switch.
 /// </summary>
 /// <remarks>
 /// WARNING: this indexer is not equivalent to IsParameterizedSwitchSet, and is not light-weight.
 /// </remarks>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>
 /// An array of all the detected parameters for the given switch, or an empty array (NOT null), if the switch has not yet
 /// been detected on the command line.
 /// </returns>
 internal string[] this[ParameterizedSwitch parameterizedSwitch]
 {
     get
     {
         // if switch has not yet been detected
         if (_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg == null)
         {
             // return an empty parameter list
             return(s_noParameters);
         }
         else
         {
             // return an array of all detected parameters
             return((string[])_parameterizedSwitches[(int)parameterizedSwitch].parameters.ToArray(typeof(string)));
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Initializes struct data.
 /// </summary>
 /// <param name="switchNames"></param>
 /// <param name="parameterizedSwitch"></param>
 /// <param name="duplicateSwitchErrorMessage"></param>
 /// <param name="multipleParametersAllowed"></param>
 /// <param name="missingParametersErrorMessage"></param>
 /// <param name="unquoteParameters"></param>
 internal ParameterizedSwitchInfo
 (
     string[] switchNames,
     ParameterizedSwitch parameterizedSwitch,
     string duplicateSwitchErrorMessage,
     bool multipleParametersAllowed,
     string missingParametersErrorMessage,
     bool unquoteParameters
 )
 {
     this.switchNames = switchNames;
     this.duplicateSwitchErrorMessage   = duplicateSwitchErrorMessage;
     this.multipleParametersAllowed     = multipleParametersAllowed;
     this.missingParametersErrorMessage = missingParametersErrorMessage;
     this.unquoteParameters             = unquoteParameters;
     this.parameterizedSwitch           = parameterizedSwitch;
 }
Пример #7
0
 /// <summary>
 /// Gets the command line argument (if any) in which the given parameterized switch was detected.
 /// </summary>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>The switch text, or null if switch was not detected on the command line.</returns>
 internal string GetParameterizedSwitchCommandLineArg(ParameterizedSwitch parameterizedSwitch)
 {
     return(_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg);
 }
Пример #8
0
        /// <summary>
        /// If the specified parameterized switch is set, returns the array of parameters.
        /// Otherwise, if the specified parameterless switch is set, returns an empty array.
        /// Otherwise returns null.
        /// This allows for example "/flp:foo=bar" to imply "/fl".
        /// </summary>
        private string[] GetSpecificFileLoggerParameters(ParameterlessSwitch parameterlessSwitch, ParameterizedSwitch parameterizedSwitch)
        {
            string[] result = null;

            if (IsParameterizedSwitchSet(parameterizedSwitch))
            {
                result = this[parameterizedSwitch];
            }
            else if (IsParameterlessSwitchSet(parameterlessSwitch))
            {
                result = Array.Empty <string>();
            }

            return(result);
        }
Пример #9
0
 /// <summary>
 /// Indicates if the given switch that takes parameters has already been detected on the command line.
 /// </summary>
 /// <remarks>This method is very light-weight.</remarks>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>true, if switch has been seen before</returns>
 internal bool IsParameterizedSwitchSet(ParameterizedSwitch parameterizedSwitch)
 {
     return(_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg != null);
 }
Пример #10
0
 private string[] GetSpecificFileLoggerParameters(ParameterlessSwitch parameterlessSwitch, ParameterizedSwitch parameterizedSwitch)
 {
     string[] strArray = null;
     if (this.IsParameterizedSwitchSet(parameterizedSwitch))
     {
         return(this[parameterizedSwitch]);
     }
     if (this.IsParameterlessSwitchSet(parameterlessSwitch))
     {
         strArray = new string[0];
     }
     return(strArray);
 }
Пример #11
0
 /// <summary>
 /// Gets the command line argument (if any) in which the given parameterized switch was detected.
 /// </summary>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>The switch text, or null if switch was not detected on the command line.</returns>
 internal string GetParameterizedSwitchCommandLineArg(ParameterizedSwitch parameterizedSwitch)
 {
     return _parameterizedSwitches[(int)parameterizedSwitch].commandLineArg;
 }
Пример #12
0
        /// <summary>
        /// If the specified parameterized switch is set, returns the array of parameters.
        /// Otherwise, if the specified parameterless switch is set, returns an empty array.
        /// Otherwise returns null.
        /// This allows for example "/flp:foo=bar" to imply "/fl".
        /// </summary>
        private string[] GetSpecificFileLoggerParameters(ParameterlessSwitch parameterlessSwitch, ParameterizedSwitch parameterizedSwitch)
        {
            string[] result = null;

            if (IsParameterizedSwitchSet(parameterizedSwitch))
            {
                result = this[parameterizedSwitch];
            }
            else if (IsParameterlessSwitchSet(parameterlessSwitch))
            {
                result = new string[] { };
            }

            return result;
        }
Пример #13
0
 /// <summary>
 /// Gets the parameters (if any) detected on the command line for the given parameterized switch.
 /// </summary>
 /// <remarks>
 /// WARNING: this indexer is not equivalent to IsParameterizedSwitchSet, and is not light-weight.
 /// </remarks>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>
 /// An array of all the detected parameters for the given switch, or an empty array (NOT null), if the switch has not yet
 /// been detected on the command line.
 /// </returns>
 internal string[] this[ParameterizedSwitch parameterizedSwitch]
 {
     get
     {
         // if switch has not yet been detected
         if (_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg == null)
         {
             // return an empty parameter list
             return s_noParameters;
         }
         else
         {
             // return an array of all detected parameters
             return (string[])_parameterizedSwitches[(int)parameterizedSwitch].parameters.ToArray(typeof(string));
         }
     }
 }
Пример #14
0
 /// <summary>
 /// Indicates if the given switch that takes parameters has already been detected on the command line.
 /// </summary>
 /// <remarks>This method is very light-weight.</remarks>
 /// <param name="parameterizedSwitch"></param>
 /// <returns>true, if switch has been seen before</returns>
 internal bool IsParameterizedSwitchSet(ParameterizedSwitch parameterizedSwitch)
 {
     return (_parameterizedSwitches[(int)parameterizedSwitch].commandLineArg != null);
 }
Пример #15
0
        /// <summary>
        /// Identifies/detects a switch that takes parameters.
        /// </summary>
        /// <param name="switchName"></param>
        /// <param name="parameterizedSwitch">[out] switch identifier (from ParameterizedSwitch enumeration)</param>
        /// <param name="duplicateSwitchErrorMessage"></param>
        /// <param name="multipleParametersAllowed"></param>
        /// <param name="missingParametersErrorMessage"></param>
        /// <param name="unquoteParameters"></param>
        /// <returns>true, if switch is a recognized switch that takes parameters</returns>
        internal static bool IsParameterizedSwitch
        (
            string switchName,
            out ParameterizedSwitch parameterizedSwitch,
            out string duplicateSwitchErrorMessage,
            out bool multipleParametersAllowed,
            out string missingParametersErrorMessage,
            out bool unquoteParameters
        )
        {
            parameterizedSwitch = ParameterizedSwitch.Invalid;
            duplicateSwitchErrorMessage = null;
            multipleParametersAllowed = false;
            missingParametersErrorMessage = null;
            unquoteParameters = false;

            foreach (ParameterizedSwitchInfo switchInfo in s_parameterizedSwitchesMap)
            {
                foreach (string parameterizedSwitchName in switchInfo.switchNames)
                {
                    if (String.Compare(switchName, parameterizedSwitchName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        parameterizedSwitch = switchInfo.parameterizedSwitch;
                        duplicateSwitchErrorMessage = switchInfo.duplicateSwitchErrorMessage;
                        multipleParametersAllowed = switchInfo.multipleParametersAllowed;
                        missingParametersErrorMessage = switchInfo.missingParametersErrorMessage;
                        unquoteParameters = switchInfo.unquoteParameters;
                        break;
                    }
                }
            }

            return (parameterizedSwitch != ParameterizedSwitch.Invalid);
        }
Пример #16
0
 /// <summary>
 /// Initializes struct data.
 /// </summary>
 /// <param name="switchNames"></param>
 /// <param name="parameterizedSwitch"></param>
 /// <param name="duplicateSwitchErrorMessage"></param>
 /// <param name="multipleParametersAllowed"></param>
 /// <param name="missingParametersErrorMessage"></param>
 /// <param name="unquoteParameters"></param>
 internal ParameterizedSwitchInfo
 (
     string[] switchNames,
     ParameterizedSwitch parameterizedSwitch,
     string duplicateSwitchErrorMessage,
     bool multipleParametersAllowed,
     string missingParametersErrorMessage,
     bool unquoteParameters
 )
 {
     this.switchNames = switchNames;
     this.duplicateSwitchErrorMessage = duplicateSwitchErrorMessage;
     this.multipleParametersAllowed = multipleParametersAllowed;
     this.missingParametersErrorMessage = missingParametersErrorMessage;
     this.unquoteParameters = unquoteParameters;
     this.parameterizedSwitch = parameterizedSwitch;
 }