private void SortList() { Functions.Sort((f1, f2) => { // The first function in the list should be the most specialiced. // If the execute the command we will iterate through the list from the beginning // and choose the first matching function. // Sort out special arguments // and remove the nullable wrapper var params1 = (from p in f1.CommandParameter where !FunctionCommand.SpecialTypes.Contains(p) select FunctionCommand.UnwrapType(p)).ToList(); var params2 = (from p in f2.CommandParameter where !FunctionCommand.SpecialTypes.Contains(p) select FunctionCommand.UnwrapType(p)).ToList(); for (int i = 0; i < params1.Count; i++) { // Prefer functions with higher parameter count if (i >= params2.Count) { return(-1); } int i1 = Array.IndexOf(TypeOrder, params1[i]); if (i1 == -1) { i1 = TypeOrder.Length; } int i2 = Array.IndexOf(TypeOrder, params2[i]); if (i2 == -1) { i2 = TypeOrder.Length; } // Prefer lower argument if (i1 < i2) { return(-1); } if (i1 > i2) { return(1); } } if (params2.Count > params1.Count) { return(1); } return(0); }); }
public void RemoveCommand(FunctionCommand command) => Functions.Remove(command);
public void AddCommand(FunctionCommand command) { Functions.Add(command); SortList(); }