public static void RegisterHook(PropertyInfo prop, UsageHook hook) { if (prop == null) { if (GlobalUsageHooks.Contains(hook) == false) { GlobalUsageHooks.Add(hook); } } else { List <UsageHook> hookCollection; if (ExplicitPropertyHooks.TryGetValue(prop, out hookCollection) == false) { hookCollection = new List <UsageHook>(); ExplicitPropertyHooks.Add(prop, hookCollection); } if (hookCollection.Contains(hook) == false) { hookCollection.Add(hook); } } }
/// <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); }