Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lab4prim
- {
- public class Car
- {
- public string model { get; set; }
- public Engine motor { get; set; }
- public int year { get; set; }
- public Car() { }
- public Car(string model, Engine motor, int year)
- {
- this.model = model;
- this.motor = motor;
- this.year = year;
- }
- }
- public class Engine
- {
- public double displacement { get; set; }
- public double horsePower { get; set; }
- public string model { get; set; }
- public Engine() { }
- public Engine(double displacement, double horsePower, string model)
- {
- this.displacement = displacement;
- this.horsePower = horsePower;
- this.model = model;
- }
- public override string ToString()
- {
- return model + " ("+horsePower.ToString()+")";
- }
- }
- public class mojaBindowanaLista<T> : BindingList<T>
- {
- private bool isSorted;
- private PropertyDescriptor sortProperty;
- private ListSortDirection sortDirection;
- public mojaBindowanaLista(IEnumerable<T> enumerable)
- {
- foreach (var el in enumerable)
- Items.Add(el);
- }
- protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
- {
- List<T> itemsList = (List<T>)this.Items;
- if (property.PropertyType.GetInterface("IComparable") != null)
- {
- itemsList.Sort(new Comparison<T>(delegate (T x, T y)
- {
- if (property.GetValue(x) != null)
- return ((IComparable)property.GetValue(x)).CompareTo(property.GetValue(y)) * (direction == ListSortDirection.Descending ? -1 : 1);
- else if (property.GetValue(y) != null)
- return ((IComparable)property.GetValue(y)).CompareTo(property.GetValue(x)) * (direction == ListSortDirection.Descending ? 1 : -1);
- else
- return 0;
- }));
- }
- isSorted = true;
- sortProperty = property;
- sortDirection = direction;
- }
- protected override bool SupportsSearchingCore
- {
- get { return true; }
- }
- protected override bool SupportsSortingCore
- {
- get
- {
- return true;
- }
- }
- protected override int FindCore(PropertyDescriptor prop, object key)
- {
- if (prop.PropertyType.GetInterface("IComparable") != null)
- return -1;
- PropertyInfo propInfo = typeof(T).GetProperty(prop.Name);
- T item;
- int found = -1;
- var selectedIndices = new ArrayList();
- if (key != null)
- {
- for (int i = 0; i < Count; ++i)
- {
- item = (T)Items[i];
- if (propInfo.GetValue(item, null).Equals(key))
- {
- found = 0;
- selectedIndices.Add(i);
- }
- }
- }
- return found;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement