Changeset 6103 for trunk/sources/HeuristicLab.Common
- Timestamp:
- 05/03/11 11:04:02 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Common/3.3
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
r5837 r6103 121 121 <Compile Include="Content\IStorableContent.cs" /> 122 122 <Compile Include="Constants.cs" /> 123 <Compile Include="ObjectExtensions.cs" /> 123 124 <Compile Include="DeepCloneable.cs" /> 124 125 <Compile Include="Content\IContent.cs" /> -
trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs
r5445 r6103 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 public static IEnumerable<FieldInfo> GetAllFields(this Type type) { 50 foreach(var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) 51 yield return field; 52 53 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 54 yield return field; 55 56 if (type.BaseType != null) { 57 foreach (var field in type.BaseType.GetAllFields()) 58 yield return field; 59 } 60 } 61 // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class 62 public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) { 63 while (toCheck != typeof(object)) { 64 var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; 65 if (generic == cur) { 66 return true; 67 } 68 toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface 69 if (toCheck == null) 70 return false; 71 } 72 return false; 73 } 47 74 } 48 75 }
Note: See TracChangeset
for help on using the changeset viewer.