Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace Lab4prim
  11. {
  12. public class Car
  13. {
  14. public string model { get; set; }
  15. public Engine motor { get; set; }
  16. public int year { get; set; }
  17.  
  18. public Car() { }
  19. public Car(string model, Engine motor, int year)
  20. {
  21. this.model = model;
  22. this.motor = motor;
  23. this.year = year;
  24. }
  25.  
  26. }
  27.  
  28. public class Engine
  29. {
  30. public double displacement { get; set; }
  31. public double horsePower { get; set; }
  32. public string model { get; set; }
  33.  
  34. public Engine() { }
  35. public Engine(double displacement, double horsePower, string model)
  36. {
  37. this.displacement = displacement;
  38. this.horsePower = horsePower;
  39. this.model = model;
  40. }
  41. public override string ToString()
  42. {
  43. return model + " ("+horsePower.ToString()+")";
  44. }
  45. }
  46.  
  47.  
  48.  
  49. public class mojaBindowanaLista<T> : BindingList<T>
  50. {
  51. private bool isSorted;
  52. private PropertyDescriptor sortProperty;
  53. private ListSortDirection sortDirection;
  54.  
  55. public mojaBindowanaLista(IEnumerable<T> enumerable)
  56. {
  57. foreach (var el in enumerable)
  58. Items.Add(el);
  59. }
  60. protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
  61. {
  62. List<T> itemsList = (List<T>)this.Items;
  63. if (property.PropertyType.GetInterface("IComparable") != null)
  64. {
  65. itemsList.Sort(new Comparison<T>(delegate (T x, T y)
  66. {
  67. if (property.GetValue(x) != null)
  68. return ((IComparable)property.GetValue(x)).CompareTo(property.GetValue(y)) * (direction == ListSortDirection.Descending ? -1 : 1);
  69. else if (property.GetValue(y) != null)
  70. return ((IComparable)property.GetValue(y)).CompareTo(property.GetValue(x)) * (direction == ListSortDirection.Descending ? 1 : -1);
  71. else
  72. return 0;
  73. }));
  74. }
  75.  
  76. isSorted = true;
  77. sortProperty = property;
  78. sortDirection = direction;
  79.  
  80. }
  81. protected override bool SupportsSearchingCore
  82. {
  83. get { return true; }
  84. }
  85. protected override bool SupportsSortingCore
  86. {
  87. get
  88. {
  89. return true;
  90. }
  91. }
  92. protected override int FindCore(PropertyDescriptor prop, object key)
  93. {
  94. if (prop.PropertyType.GetInterface("IComparable") != null)
  95. return -1;
  96. PropertyInfo propInfo = typeof(T).GetProperty(prop.Name);
  97. T item;
  98. int found = -1;
  99. var selectedIndices = new ArrayList();
  100. if (key != null)
  101. {
  102. for (int i = 0; i < Count; ++i)
  103. {
  104. item = (T)Items[i];
  105. if (propInfo.GetValue(item, null).Equals(key))
  106. {
  107. found = 0;
  108. selectedIndices.Add(i);
  109. }
  110. }
  111. }
  112. return found;
  113. }
  114.  
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement