Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 624857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:14:46+00:00 2026-05-13T19:14:46+00:00

I read this question: Command Line Parser for .NET . I thought that was

  • 0

I read this question: Command Line Parser for .NET.

I thought that was what I was looking for, but the library Command Line Parser Library is not Compact framework friendly…

I REALLY don’t want to write a CL parser and I have been drifting away from the real purpose of my little app because of this unfortunate trial.

Does someone know of a library that fits the compact-framework? (preferably with simplicity and functionality like the one mentioned above)
Does not matter whether version 2 or 3.5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:14:46+00:00Added an answer on May 13, 2026 at 7:14 pm

    This is what I’m using. I borrowed it from somewhere, but not sure where:

    using System.Collections.Specialized;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Parses the command line arguments into a name/value collection
    /// </summary>
    public class CommandLineArgumentParser
    {
        #region Fields
        private StringDictionary parameters;
        #endregion
    
        #region Constructors
        /// <summary>
        ///     Initializes a new instance of the <see cref="CommandLineArgumentParser"/> class.
        /// </summary>
        /// <param name="args">command-line arguments
        /// </param>
        public CommandLineArgumentParser(string[] args)
        {
            this.parameters = new StringDictionary();
            Regex spliter = new Regex(@"^-{1,2}|^/|=|:", RegexOptions.IgnoreCase | RegexOptions.Compiled);
    
            Regex remover = new Regex(@"^['""]?(.*?)['""]?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
    
            string parameter = null;
            string[] parts;
    
            // Valid parameters forms:
            // {-,/,--}param{ ,=,:}((",')value(",'))
            // Examples: 
            // -param1 value1 --param2 /param3:"Test-:-work" 
            //   /param4=happy -param5 '--=nice=--'
            foreach (string txt in args)
            {
                // Look for new parameters (-,/ or --) and a
                // possible enclosed value (=,:)
                parts = spliter.Split(txt, 3);
    
                switch (parts.Length)
                {
                    // Found a value (for the last parameter 
                    // found (space separator))
                    case 1:
                        if (parameter != null)
                        {
                            if (!this.parameters.ContainsKey(parameter))
                            {
                                parts[0] = remover.Replace(parts[0], "$1");
    
                                this.parameters.Add(parameter, parts[0]);
                            }
    
                            parameter = null;
                        }
    
                        // else Error: no parameter waiting for a value (skipped)
                        break;
    
                    // Found just a parameter
                    case 2:
                        // The last parameter is still waiting. 
                        // With no value, set it to true.
                        if (parameter != null)
                        {
                            if (!this.parameters.ContainsKey(parameter))
                            {
                                this.parameters.Add(parameter, "true");
                            }
                        }
    
                        parameter = parts[1];
                        break;
    
                    // Parameter with enclosed value
                    case 3:
                        // The last parameter is still waiting. 
                        // With no value, set it to true.
                        if (parameter != null)
                        {
                            if (!this.parameters.ContainsKey(parameter))
                            {
                                this.parameters.Add(parameter, "true");
                            }
                        }
    
                        parameter = parts[1];
    
                        // Remove possible enclosing characters (",')
                        if (!this.parameters.ContainsKey(parameter))
                        {
                            parts[2] = remover.Replace(parts[2], "$1");
                            this.parameters.Add(parameter, parts[2]);
                        }
    
                        parameter = null;
                        break;
                }
            }
    
            // In case a parameter is still waiting
            if (parameter != null)
            {
                if (!this.parameters.ContainsKey(parameter))
                {
                    this.parameters.Add(parameter, "true");
                }
            }
        }
        #endregion
    
        #region Properties
        /// <summary>
        /// Gets a count of command line arguments
        /// </summary>
        public int Count
        {
            get
            {
                return this.parameters.Count;
            }
        }
    
        /// <summary>
        /// Gets the value with the given parameter name
        /// </summary>
        /// <param name="param">name of the parameter</param>
        /// <returns>the value of the parameter</returns>
        public string this[string param]
        {
            get
            {
                return this.parameters[param];
            }
        }
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read this question but it's not quite what I was looking for.
I read this question but the answer does not perform a refactoring of the
I have read this question and the simple and clear answer but it's not
Having read this question Immutable or not immutable? and reading answers to my previous
I've read this question, but I want to know how can I delete the
I've already read this question and this question and this , but none of
Question 1 I used to use that line for my PHP parser file for
This question has been asked more than once before, but I have not found
I read this question in stackoverflow. The excerpt answer provided by bbum is below:
You can read this question where I ask about the best architecture for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.