void LoadCommandContainer(TypeDescriptor containerType, AssemblyDescriber describer) { if (containerType.IsAbstract || !containerType.HasPublicParameterlessConstructor) { return; } var methods = describer.GetPublicMethods(containerType); var cmdMethods = (from method in methods let commandAttr = method.APIAttributes.OfType <CommandAttribute>().FirstOrDefault() where commandAttr != null select new { method, commandAttr }).ToArray(); if (cmdMethods.Length == 0) { return; } var dupeCommandNames = from i in cmdMethods group i by i.commandAttr.Name into g where g.Count() > 1 select g; if (dupeCommandNames.Any()) { throw new LoaderItemInitException(string.Format("Duplicate command names in container {0}", containerType)); } var container = CreateLoaderInstance <CommandContainer>(containerType); var commandInfos = new List <LoaderCommand>(); foreach (var method in cmdMethods) { try { var reflectedCmd = new ReflectedCommand(container, method.method, method.commandAttr); var lcInfo = new LoaderCommand(this, reflectedCmd); reflectedCmd.LoaderCommand = lcInfo; commandInfos.Add(lcInfo); } catch (Exception ex) { Debug.WriteLine("Could not initialize command {0} in container {1}: {2}", method.method.Name, containerType, ex.Message); } } var lccInfo = new LoaderCommandContainer(this, container, containerType); ExtensionStore.InitCommandContainer(lccInfo, commandInfos); container.Initialize(Hooks); AddItems(commandInfos); AddItem(lccInfo); }
public void PositionalStringParameterGetsPickedUp() { var command = new ReflectedCommand<object>(typeof(PositionalString), _factory); command.PositionalParameters.Count.ShouldBe(1); var param = command.PositionalParameters[0]; param.PropertyName.ShouldBe("Stuff"); param.IsRequired.ShouldBe(false); param.IsList.ShouldBe(false); }
public void NamedBoolParameterGetsPickedUp() { var command = new ReflectedCommand<object>(typeof(NamedBool), _factory); command.NamedParameters.Count.ShouldBe(1); var param = command.NamedParameters[0]; param.PropertyName.ShouldBe("Flag"); param.IsBool.ShouldBe(true); param.HasLongName("flag").ShouldBe(true); }
public void NamedLongParameterGetsPickedUp() { var command = new ReflectedCommand<object>(typeof(NamedLong), _factory); command.NamedParameters.Count.ShouldBe(1); var param = command.NamedParameters[0]; param.PropertyName.ShouldBe("Num"); param.IsBool.ShouldBe(false); param.HasLongName("magic").ShouldBe(true); param.HasShortName("n").ShouldBe(true); }
/// <summary>Determines whether the specified ReflectedCommand is equal to the current ReflectedCommand.</summary> /// <returns>true if the specified ReflectedCommand is equal to the current ReflectedCommand; otherwise, false.</returns> /// <param name="other">The ReflectedCommand to compare with the current ReflectedCommand.</param> /// <filterpriority>2</filterpriority> protected bool Equals(ReflectedCommand other) { return(Equals(Value, other.Value)); }
public void DoubleWordClassGetsProperVerbs() { var command = new ReflectedCommand<object>(typeof(TwoWords), _factory); command.Verbs.ShouldBe(new[] { "two", "words" }); }
public void SingleWordCommandGetsProperVerbs() { var command = new ReflectedCommand<object>(typeof(SingleCommand), _factory); command.Verbs.ShouldBe(new[] { "single" }); }
public void RequiredParameterIsMarkedAsRequired() { var command = new ReflectedCommand<object>(typeof(PositionalRequired), _factory); command.PositionalParameters.Count.ShouldBe(1); var param = command.PositionalParameters[0]; param.IsRequired.ShouldBe(true); }