/// <summary> /// Constructor with index selection. /// </summary> /// <param name="isIndexSatisfied"></param> /// <param name="select"></param> public DelegateExpression(Predicate2 <uint, Dictionary <string, object> > isIndexSatisfied, [NotNull] SelectDelegate <Selectable, T> select, Action <List <Selectable> > sort) { this.isIndexSatisfied = isIndexSatisfied; this.select = select; this.sort = sort; }
/// <summary> /// Constructor with satisfication and selection. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public JoinDelegateExpression(Predicate <T> isSatisfied, [NotNull] SelectDelegate <Selectable, T> select, JoinKeyDelegate <Key, T> join) : base(isSatisfied, select) { this.joinKey = join; }
/// <summary> /// Constructor with index selection. /// </summary> /// <param name="isIndexSatisfied"></param> /// <param name="select"></param> public JoinDelegateExpression(Predicate2 <uint, Dictionary <string, object> > isIndexSatisfied, Predicate <T> isSatisfied, [NotNull] SelectDelegate <Selectable, T> select, Action <List <Selectable> > sort, JoinKeyDelegate <Key, T> join) : base(isIndexSatisfied, isSatisfied, select, sort) { this.joinKey = join; }
/// <summary> /// Constructor with satisfication and selection. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public DelegateExpression(Predicate <T> isSatisfied, [NotNull] SelectDelegate <Selectable, T> select, Action <List <Selectable> > sort) { this.isSatisfied = isSatisfied; this.select = select; this.sort = sort; }
public VehicleDetailPickerModel(SelectDelegate selectionHandler, int Max) { ReturnSelection = selectionHandler; SelectionItems = new List <string>(); for (int i = 0; i <= Max; i++) { SelectionItems.Add(i.ToString()); } }
//public static bool Any<T>(this T[] array, PredicateDelegate<T> predicate) => array.ToList().Any(predicate); public static List <TOut> Select <TIn, TOut>(this IEnumerable <TIn> input, SelectDelegate <TIn, TOut> select) { var list = new List <TOut>(); foreach (var thing in input) { select(thing, out var result); list.Add(result); } return(list); }
public SaveDataButton(string name, Base.GameState state, SelectDelegate select) : base(name) { _shadow = GameContent.LoadContent <Texture2D>("gui/gui_shadow.png"); _magic = GameContent.LoadContent <Texture2D>("gui/gui_background.png"); _fullHealth = GameContent.LoadContent <Texture2D>("gui/health_full.png"); _emptyHealth = GameContent.LoadContent <Texture2D>("gui/health_empty.png"); _partHealth = GameContent.LoadContent <Texture2D>("gui/health_part.png"); Font = GameContent.LoadContent <SpriteFont>("fonts/DefaultFont"); Data = state; Select += select; }
///Use delegate implement select student ///Share basic select logic ///Use delegate to decouple and reduces duplication of code. private List <Student> GetListDelegate(List <Student> source, SelectDelegate method) { List <Student> result = new List <Student>(); foreach (Student student in source) { if (method.Invoke(student)) { result.Add(student); } } return(result); }
private ItemValueResult Select(SelectDelegate del) { ItemValueResult res = null; if (acc.Count > 0) { res = new ItemValueResult(acc[0]); for (int i = 1; i < acc.Count; i++) { del(acc[i], ref res); } } return(res); }
public WorkCollection <T> Select(SelectDelegate selectDelegate) { WorkCollection <T> workCollection = new WorkCollection <T>(); foreach (var item in this) { bool isSelect = selectDelegate(item); if (isSelect) { workCollection.Add(item); } } return(workCollection); }
private VehicleDetailPickerModel InstantiatePicker(SelectDelegate Handler, object PickerData) { if (PickerData is int) { return(new VehicleDetailPickerModel(Handler, (int)PickerData)); } else if (PickerData is List <string> ) { return(new VehicleDetailPickerModel(Handler, (List <string>)PickerData)); } else { throw new Exception("Invalid Picker Data Set"); } }
static void Main() { Test previous = new Test(6); List <Test> collection = new List <Test>(); FilterDelegate <Test> filter = Filter; SelectDelegate <Test> select = Select; for (int i = 0; i < 10; i++) { collection.Add(new Test(i)); } // use explicit types to be able to use ref in lambda CombinedDelegate <Test> combined = (IEnumerable <Test> c, ref Test p) => @select(filter(c), ref p); Test result = combined(collection, ref previous); //Expected result Test with Number = 7 }
private void BuildPicker(SelectDelegate SelectionHandler, object PickerData) { UIPickerView customPickerView = new UIPickerView(CGRect.Empty) { AutoresizingMask = UIViewAutoresizing.FlexibleWidth, Model = InstantiatePicker(SelectionHandler, PickerData), ShowSelectionIndicator = true, BackgroundColor = UIColor.White, Hidden = true }; customPickerView.Frame = PickerFrameWithSize(customPickerView.SizeThatFits(CGSize.Empty)); View.AddSubview(customPickerView); customPickerView.Hidden = false; currentPicker = customPickerView; }
static void Main(string[] args) { var list = new List <int>(); //数据源:-5至4的所有整数 list.AddRange(Enumerable.Range(-5, 10)); //2.指向 SelectDelegate sd = Select; //3.调用 list = sd.Invoke(list, 1); //只有大于1的整数被选中 Console.WriteLine("列表中有{0}个数字.", list.Count); Console.ReadKey(); }
public Tape(int width, int height = 72, int cellsCount = 20) { Size = new Size(width, height); BorderStyle = BorderStyle.FixedSingle; Cells = new LinkedList <Cell>(); Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; for (int i = 0; i < cellsCount / 2; i++) { AddCell(Direction.Left); } Pointer = Cells.Last; for (int i = 0; i < cellsCount / 2; i++) { AddCell(Direction.Right); } Regex = InitializeRegex(); CurrentState = "q1"; MoveStatic = MoveTape; SelectStatic = Select; ChangePointerOnClickStatic = ChangePointerOnClick; }
public void Show() { List <Student> studentList = this.GetStudentList(); { SelectDelegate selectDelegate = new SelectDelegate(this.AgeCondition); List <Student> result = this.GetListDelegate(studentList, selectDelegate); Console.WriteLine($"{result.Count()} students is found by age."); } { SelectDelegate selectDelegate = new SelectDelegate(this.LengthThan); List <Student> result = this.GetListDelegate(studentList, selectDelegate); Console.WriteLine($"{result.Count()} students is found by length of name."); } { SelectDelegate selectDelegate = new SelectDelegate(this.AllThan); List <Student> result = this.GetListDelegate(studentList, selectDelegate); Console.WriteLine($"{result.Count()} students is found by both length of name and age."); } }
// This is unrelated to settings windows but it's a nice bonus feature using the same code. // However for reasons unknown, it doesn't work. Worth investigating. //[MenuItem("Window/New inspector from selection")] //public static void NewInspectorFromSelection() //{ // ShowInspector(SelectUnityObject, Selection.objects); //} //public static string SelectUnityObject(object o) //{ // // Selection didn't change, so there's nothing to do here except return a window title // Selection.objects = o as UnityEngine.Object[]; // if (Selection.activeObject != null) // { // return Selection.activeObject.name; // } // return null; //} public static void ShowInspector(SelectDelegate select, object arg) { //Type inspectorType = Type.GetType("UnityEditor.InspectorWindow, UnityEditor"); EditorWindow inspector = ScriptableObject.CreateInstance("UnityEditor.InspectorWindow") as EditorWindow; // Before activating the settings window, save our old selection so we can restore it UnityEngine.Object[] oldSelection = Selection.objects; string title = select(arg); bool successfullySetLock = false; if (inspector != null) { // Use reflection (InspectorWindow is inaccessible due to internal protection level) // to lock the inspector we created so it doesn't change its selection when we // restore our selection back to normal Type inspectorType = inspector.GetType(); PropertyInfo isLockedProperty = inspectorType.GetProperty("isLocked"); if (isLockedProperty != null) { MethodInfo setter = isLockedProperty.GetSetMethod(); if (setter != null) { try { setter.Invoke(inspector, new object[] { true }); successfullySetLock = true; } catch { successfullySetLock = false; } } } // TODO: Try to dock the window? That's more private APIs though. // Change the new window's title to match the settings being edited // TODO: Unfortunately, this only persists until the next script recompile. // There's not really a reliable way to get a list of inspector windows though, so this might prove tricky to fix. if (title != null) { inspector.titleContent = new GUIContent(inspector.titleContent); inspector.titleContent.text = title; inspector.titleContent.image = null; } } else { Debug.LogError("Failed to create InspectorWindow. Did the private API change?"); } if (successfullySetLock) { // Only restore the selection if the lock on the window was set successfully, otherwise the settings window that was requested won't even show up Selection.objects = oldSelection; } else { Debug.LogError("Looks like something changed in the InspectorWindow's private API. This settings shortcut may not work correctly."); } }
/// <summary> /// Constructor with select only. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public JoinDelegateExpression([NotNull] SelectDelegate <Selectable, T> select, Action <List <Selectable> > sort, JoinKeyDelegate <Key, T> join) : base(select, sort) { this.joinKey = join; }
public Button(string text, SelectDelegate select) : base(text) { Font = GameContent.LoadContent <SpriteFont>("fonts/SmallFont"); Text = text; Select += select; }
/// <summary> /// Constructor with select only. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public DelegateExpression([NotNull] SelectDelegate <Selectable, T> select, Action <List <Selectable> > sort) { this.select = select; this.sort = sort; }
public VehicleDetailPickerModel(SelectDelegate selectionHandler, List <string> Options) { ReturnSelection = selectionHandler; SelectionItems = Options; }
/// <summary> /// Constructor with select only. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public DelegateExpression([NotNull] SelectDelegate <Selectable, T> select) { this.select = select; }
/// <summary> /// Constructor with satisfication and selection. /// </summary> /// <param name="isSatisfied"></param> /// <param name="select"></param> public DelegateExpression(Predicate <T> isSatisfied, [NotNull] SelectDelegate <Selectable, T> select) { this.isSatisfied = isSatisfied; this.select = select; }
/// <summary> /// Распарсить отмеченные (галочкой) ячейки гриды в коллекцию объектов. /// </summary> /// <typeparam name="T">Тип объекта</typeparam> /// <param name="dgv">Грида</param> /// <param name="SelectionColumnName">Имя колонки, в которой находятся галочки (CheckBoxCell)</param> /// <param name="Selector">Селектор, для преобразования объектов, лежащих в ячейках, к результирующему типу T</param> /// <returns>Коллекция объектов</returns> public static List <T> GetItemsFromCheckedRowsTags <T>(DataGridView dgv, string SelectionColumnName, SelectDelegate <T> Selector) where T : class { List <T> result = new List <T>(); foreach (DataGridViewRow row in dgv.Rows) { DataGridViewCheckBoxCell cell = row.Cells[SelectionColumnName] as DataGridViewCheckBoxCell; if (cell != null) { T temp = Selector(row.Tag); if (temp != null) { if (cell.Value != null && (bool)cell.Value) { result.Add(temp); } } } } return(result); }