예제 #1
0
 /// <summary>
 /// Get the shortcut value given a property info object.  This can only be called after one of the Args methods
 /// has parsed the parent type at least once.  Otherwise you will get an InvalidArgDefinitionException.k
 /// </summary>
 /// <param name="info">The property whose shortcut you want to get.</param>
 /// <returns>The shortcut for the property</returns>
 public static string GetShortcut(PropertyInfo info)
 {
     if (RegisteredTypes.Contains(info.DeclaringType) == false)
     {
         // Ensures that the shortcuts get registered
         try { Args.Parse(info.DeclaringType); } catch (Exception) { }
     }
     if (KnownShortcuts.ContainsKey(info))
     {
         return(KnownShortcuts[info]);
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
        /// <summary>
        /// Creates a new ArgLongForm attirbute using the given long form string.
        /// </summary>
        /// <param name="value">The long form value.  You can provide the two dashes in this string or not.  The --long-form pattern will enforced at runtime either way.</param>
        public ArgLongForm(string value)
        {
            this.BeforeParsePriority = 100;
            if (value == null)
            {
                throw new InvalidArgDefinitionException("Values for long form arguments cannot be null", new ArgumentNullException("value"));
            }
            if (value.StartsWith("--"))
            {
                value = value.Substring(2);
            }

            this.value = value;

            var myUsageHook = new UsageHook();

            myUsageHook.HookExecuting += (usageInfo) =>
            {
                if (target == null)
                {
                    // This should ensure that the target should be populated if the current property is the target
                    try { Args.Parse(usageInfo.Property.PropertyType); } catch (Exception) { }
                }

                if (target == null)
                {
                    return;
                }

                if (usageInfo.Property == target)
                {
                    usageInfo.Aliases.Add("--" + this.value);
                }
            };

            ArgUsage.RegisterHook(null, myUsageHook);
        }