wasSharpNET – Diff between revs 11 and 27

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 11 Rev 27
Line 29... Line 29...
29   29  
30 foreach (var fi in @object.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) 30 foreach (var fi in @object.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
31 { 31 {
32 if (fi.FieldType.FullName.Split('.', '+') 32 if (fi.FieldType.FullName.Split('.', '+')
33 .Contains(@namespace, StringComparer.OrdinalIgnoreCase)) -  
34 { 33 .Contains(@namespace, StringComparer.OrdinalIgnoreCase))
35 foreach (var sf in wasGetFields(fi.GetValue(@object), @namespace)) -  
36 { 34 foreach (var sf in wasGetFields(fi.GetValue(@object), @namespace))
37 yield return sf; -  
38 } -  
39 } 35 yield return sf;
40 yield return new KeyValuePair<FieldInfo, object>(fi, @object); 36 yield return new KeyValuePair<FieldInfo, object>(fi, @object);
41 } 37 }
Line 42... Line 38...
42 } 38 }
Line 62... Line 58...
62 .Contains(@namespace, StringComparer.OrdinalIgnoreCase)) 58 .Contains(@namespace, StringComparer.OrdinalIgnoreCase))
63 { 59 {
64 var getMethod = pi.GetGetMethod(); 60 var getMethod = pi.GetGetMethod();
65 if (getMethod.ReturnType.IsArray) 61 if (getMethod.ReturnType.IsArray)
66 { 62 {
67 var array = (Array)getMethod.Invoke(@object, null); 63 var array = (Array) getMethod.Invoke(@object, null);
68 foreach (var sp in 64 foreach (var sp in
69 array.Cast<object>().SelectMany(element => wasGetProperties(element, @namespace))) 65 array.Cast<object>().SelectMany(element => wasGetProperties(element, @namespace)))
70 { -  
71 yield return sp; 66 yield return sp;
72 } -  
73 } 67 }
74 foreach ( 68 foreach (
75 var sp in 69 var sp in
76 wasGetProperties(pi.GetValue(@object, null), @namespace)) 70 wasGetProperties(pi.GetValue(@object, null), @namespace))
77 { -  
78 yield return sp; 71 yield return sp;
79 } -  
80 } 72 }
81 yield return new KeyValuePair<PropertyInfo, object>(pi, @object); 73 yield return new KeyValuePair<PropertyInfo, object>(pi, @object);
82 } 74 }
83 } 75 }
Line 92... Line 84...
92 /// <param name="object">the object to set the value on</param> 84 /// <param name="object">the object to set the value on</param>
93 /// <param name="value">the value to set</param> 85 /// <param name="value">the value to set</param>
94 public static void wasSetInfoValue<TK, TV>(TK info, ref TV @object, object value) 86 public static void wasSetInfoValue<TK, TV>(TK info, ref TV @object, object value)
95 { 87 {
96 object o = @object; 88 object o = @object;
97 var fi = (object)info as FieldInfo; 89 var fi = (object) info as FieldInfo;
98 if (fi != null) 90 if (fi != null)
99 { 91 {
100 fi.SetValue(o, value); 92 fi.SetValue(o, value);
101 @object = (TV)o; 93 @object = (TV) o;
102 return; 94 return;
103 } 95 }
104 var pi = (object)info as PropertyInfo; 96 var pi = (object) info as PropertyInfo;
105 if (pi != null) 97 if (pi != null)
106 { 98 {
107 pi.SetValue(o, value, null); 99 pi.SetValue(o, value, null);
108 @object = (TV)o; 100 @object = (TV) o;
109 } 101 }
110 } 102 }
Line 111... Line 103...
111   103  
112 /////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////
Line 118... Line 110...
118 /// <param name="info">either a FieldInfo or PropertyInfo</param> 110 /// <param name="info">either a FieldInfo or PropertyInfo</param>
119 /// <param name="value">the object to get from</param> 111 /// <param name="value">the object to get from</param>
120 /// <returns>the value of the field or property</returns> 112 /// <returns>the value of the field or property</returns>
121 public static object wasGetInfoValue<T>(T info, object value) 113 public static object wasGetInfoValue<T>(T info, object value)
122 { 114 {
123 var fi = (object)info as FieldInfo; 115 var fi = (object) info as FieldInfo;
124 if (fi != null) 116 if (fi != null)
125 { -  
126 return fi.GetValue(value); 117 return fi.GetValue(value);
127 } -  
128 var pi = (object)info as PropertyInfo; 118 var pi = (object) info as PropertyInfo;
129 if (pi != null) 119 if (pi != null)
130 { 120 {
131 if (pi.GetIndexParameters().Any()) 121 if (pi.GetIndexParameters().Any())
132 { -  
133 return value; 122 return value;
134 } -  
135 return pi.GetValue(value, null); 123 return pi.GetValue(value, null);
136 } 124 }
137 return null; 125 return null;
138 } 126 }
139 } 127 }
140 } 128 }
141   129