private void InitializeNamedArguments()
        {
            var props = typeof(T).GetTypeInfo().GetProperties().Where(p =>
                                                                      p.GetCustomAttribute <NamedArgumentAttribute>() != null);

            foreach (var prop in props)
            {
                var arg = prop.ToNamedArgument();

                var sn = GetShortName(arg);
                if (sn.HasValue)
                {
                    if (ShortNameArguments.ContainsKey(sn.Value))
                    {
                        throw new DuplicateArgumentException(sn.ToString());
                    }
                    ShortNameArguments.Add(sn.Value, arg);
                }

                var ln = GetLongName(arg);
                if (ln != null)
                {
                    if (LongNameArguments.ContainsKey(ln))
                    {
                        throw new DuplicateArgumentException(ln);
                    }
                    LongNameArguments.Add(ln, arg);
                }
            }
        }
Beispiel #2
0
 internal void ProcessArguments()
 {
     foreach (var arg in PendingNamedArguments)
     {
         if (arg.ShortName.HasValue)
         {
             ShortNameArguments.Add(arg.ShortName.Value, arg);
         }
         if (arg.LongName != null)
         {
             LongNameArguments.Add(arg.LongName, arg);
         }
         if (arg.Required)
         {
             RequiredNamedArguments.Add(arg.Name);
         }
     }
 }
Beispiel #3
0
        public void InitializeTriggers(IEnumerable <ITerminatingTrigger> triggers)
        {
            Triggers = triggers;
            if (triggers == null)
            {
                return;
            }

            foreach (var trigger in Triggers.Where(p => p != null))
            {
                var sn = GetShortName(trigger, String.Format(
                                          "Trigger '{0}' argument {1} is not a valid short name. {2}",
                                          trigger.PluginName, trigger.ShortName,
                                          ArgumentValidation.IsAllowedShortNameExplanation));
                if (sn.HasValue)
                {
                    if (ShortNameArguments.ContainsKey(sn.Value))
                    {
                        throw new DuplicateArgumentException(sn.ToString());
                    }
                    ShortNameArguments.Add(sn.Value, trigger);
                }

                var ln = GetLongName(trigger, String.Format(
                                         "Trigger '{0}' argument {1} is not a valid long name. {2}",
                                         trigger.PluginName, trigger.LongName,
                                         ArgumentValidation.IsAllowedLongNameExplanation));
                if (ln != null)
                {
                    if (LongNameArguments.ContainsKey(ln))
                    {
                        throw new DuplicateArgumentException(ln);
                    }
                    LongNameArguments.Add(ln, trigger);
                }
            }
        }