Ejemplo n.º 1
0
        /// <summary>
        /// Sets the property identified by longFlag's name to the value specified by its parameter (or lack thereof).
        /// </summary>
        /// <param name="longFlag">used to identify what property to change and what to set its value to</param>
        public static void SetPropertyByLongFlag(string longFlag)
        {
            KeyValuePair <string, string> keyValuePair = CliArguments.SplitLongFlag(longFlag);

            Property property = GetPropertyByLongFlag(keyValuePair.Key);

            if (property == null)
            {
                throw new ArgumentException(string.Format("unknown long flag specified: '{0}'", keyValuePair.Key));
            }

            property.SetValue(keyValuePair.Value);
        }
Ejemplo n.º 2
0
        static void FlagParseDemo(string[] args)
        {
            CliArguments cliArguments = new CliArguments(args);

            StringBuilder arguments = new StringBuilder();

            cliArguments.Arguments.ForEach(str => arguments.AppendFormat("{0} ", str));
            Console.WriteLine(string.Format("Arguments: {0}", arguments));

            Console.WriteLine(string.Format("Short Flags: {0}", cliArguments.ShortFlags));

            StringBuilder longFlags = new StringBuilder();

            cliArguments.LongFlags.ForEach(delegate(string str)
            {
                KeyValuePair <string, string> splitFlag = CliArguments.SplitLongFlag(str);
                longFlags.AppendFormat("[key:{0}; value:{1}]", splitFlag.Key, splitFlag.Value);
            });
            Console.WriteLine(string.Format("Long Flags: {0}", longFlags));

            // Prototype help display
            Configuration.Properties.ForEach(delegate(Property property)
            {
                Console.WriteLine(property.Name);
                Console.WriteLine();
                Console.WriteLine(string.Format("Flags: {0}", property.LongFlags));
                Console.WriteLine();
                Console.WriteLine(property.Description);
                Console.WriteLine("--------------------------------------------------------------------------------");
                Console.WriteLine();
            });

            Configuration.ReadLongFlags(cliArguments.LongFlags);

            Configuration.ErrorContacts.Value = "someoneElse&badDomain.com";

            Configuration.Properties.ForEach(property => Console.WriteLine(property));
        }