private void LearnForType(Type type, IActOnItem selectedAction) { var iface = GenericITypedItem(type); if (iface != null) { _learnings[KeyForType(iface)] = selectedAction; } }
public void LearnActionForCommandResult(string input, IActOnItem selectedAction, AutoCompletionResult.CommandResult result) { if (result.IsTransient()) { return; } LearnForResult(result, selectedAction); LearnForType(result.Item.GetType(), selectedAction); }
public static bool CanActOn(this IActOnItem self, IItem item) { if (!(self is ICanActOnItem)) { return(true); } return((bool)self.GetType() .GetMethod("CanActOn", BindingFlags.Instance | BindingFlags.Public, null, new[] { self.TypedItemType }, null) .Invoke(self, new object[] { item.Item })); }
private IActOnItem ActionForResult(AutoCompletionResult.CommandResult result) { IActOnItem actionForResult = null; if (result.CompletionId != null) { var sha1 = result.CompletionId.GetLearningId(); if (_learnings.ContainsKey(sha1)) { actionForResult = _learnings[sha1]; } } return(actionForResult); }
public static IItem ActOn(this IActOnItem self, IItem item) { IItem returnedValue = null; MethodInfo methodInfo = self.GetType() .GetMethod("ActOn", BindingFlags.Instance | BindingFlags.Public, null, new[] { self.TypedItemType }, null); UnwrapTargetInvocationException(() => returnedValue = methodInfo.Invoke(self, new[] { item.Item }) as IItem); if (methodInfo.ReturnType == typeof(void)) { returnedValue = NoReturnValue.Object; } return(returnedValue); }
public void AttributeStrategyForDefaultActionForFileInfoShowsDoesNotFindAction() { var act = new MockActOnFileInfo(); var defaultAct = new MockDefaultActOnFileInfo(); var run = new Run(); var info = new FileInfoItem(new FileInfo("does.not.exist")); var actions = new IActOnItem[] { act, defaultAct }; var strategy = new GetDefaultActionBasedOnAttributeForType(); strategy.Actions = actions; var getItems = new GetActionsForItem(actions, strategy); var actionsForItem = getItems.ActionsForItem(ResultForItem(info)); Assert.NotEmpty(actionsForItem); Assert.DoesNotContain(run, actionsForItem); }
private void LearnForResult(AutoCompletionResult.CommandResult result, IActOnItem selectedAction) { _learnings[result.CompletionId.GetLearningId()] = selectedAction; }
public FakeFindDefaultActionForItemStrategy(IActOnItem act) { _act = act; }
public void LearnActionForCommandResult(string input, IActOnItem selectedAction, AutoCompletionResult.CommandResult result) { if (result.IsTransient()) return; LearnForResult(result, selectedAction); LearnForType(result.Item.GetType(), selectedAction); }