Guest User

Untitled

a guest
Nov 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public class Filters {
  2. public int var1 = 1,
  3. var2 = 2,
  4. var3 = 3;
  5. }
  6.  
  7. Filters filter1 = new Filters();
  8.  
  9. foreach (var prop in filter1.props) {
  10. Console.WriteLine(filter1[prop] + 3);
  11. }
  12.  
  13. 4
  14. 5
  15. 6
  16.  
  17. public class Filters
  18. {
  19. public int var1 { get; set; } = 1;
  20. public int var2 { get; set; } = 2;
  21. public int var3 { get; set; } = 3;
  22. }
  23.  
  24. static void Main(string[] args)
  25. {
  26. Filters filter1 = new Filters();
  27.  
  28. foreach (var prop in filter1.GetType().GetProperties())
  29. {
  30. Console.WriteLine("{0}={1}", prop.Name, (int)prop.GetValue(filter1, null) + filter1.GetType().GetProperties().Length);
  31. }
  32.  
  33. Console.ReadKey();
  34. }
  35.  
  36. 4
  37. 5
  38. 6
  39.  
  40. public class Filter
  41. {
  42. public IDictionary<string, object> Properties { get; } = new Dictionary<string, object>();
  43. }
  44.  
  45. public class Filter
  46. {
  47. public int Var1 { get; set; } = 1;
  48. public int Var2 { get; set; } = 2;
  49. public int Var3 { get; set; } = 3;
  50. }
  51.  
  52. var filter = new Filter();
  53. var filterType = filter.GetType();
  54. var readableProperties = filterType.GetProperties().Where( p => p.GetGetMethod() != null );
  55.  
  56. foreach (var property in readableProperties)
  57. {
  58. var value = (int)property.GetValue( filter );
  59. Console.WriteLine( $"{property.Name} = {value + 3}" );
  60. }
  61.  
  62. FieldInfo[] fields = typeof(GeneralFilters).GetFields();
  63. for (int i = 0; i < fields.Length; i++)
  64. {
  65. //MANIPULATE HERE
  66. BlankTemplate tempFilter = (BlankTemplate)fields[i].GetValue(filters);
  67. // Ignore this for now. tempFilter.selectedItems;
  68. }
  69.  
  70. public class BlankTemplate
  71. {
  72. public string[] selectedItems;
  73. public bool selectAll = false;
  74. }
  75.  
  76. var fieldNames = Object.keys(filterObject);
  77. for (var i = 0; i < fieldNames.length; i++) {
  78. doSomething( filterObject[fieldNames[i]] );
  79. }
Add Comment
Please, Sign In to add comment