- Timestamp:
- 05/14/11 16:45:46 (13 years ago)
- Location:
- branches/histogram
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram
-
branches/histogram/HeuristicLab.Common/3.3/TypeExtensions.cs
r5445 r6195 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Reflection; 23 25 using System.Text; 24 26 … … 45 47 return sb.ToString(); 46 48 } 49 50 public static IEnumerable<FieldInfo> GetAllFields(this Type type) { 51 foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) 52 yield return field; 53 54 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 55 yield return field; 56 57 if (type.BaseType != null) { 58 foreach (var field in type.BaseType.GetAllFields()) 59 yield return field; 60 } 61 } 62 63 // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class 64 public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) { 65 while (toCheck != typeof(object)) { 66 var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; 67 if (generic == cur) { 68 return true; 69 } 70 toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface 71 if (toCheck == null) 72 return false; 73 } 74 return false; 75 } 47 76 } 48 77 }
Note: See TracChangeset
for help on using the changeset viewer.