From 45bcad49fb1d4112bb3dc0e0677e3e3484b6880d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Wed, 30 Nov 2011 15:57:57 +0100 Subject: [PATCH] Added getsubtype definitions helper method. --- .../TypeSystem/ExtensionMethods.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs b/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs index 27e4016cdb..cb6e1cb3b9 100644 --- a/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs +++ b/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs @@ -262,5 +262,26 @@ namespace ICSharpCode.NRefactory.TypeSystem return new ProjectedList(context, constantValues, (c, t) => t.Resolve(c)); } #endregion + + #region GetSubTypeDefinitions + public static IEnumerable GetSubTypeDefinitions (this IType baseType) + { + var def = baseType.GetDefinition (); + if (def == null) + return Enumerable.Empty (); + return def.GetSubTypeDefinitions (); + } + + /// + /// Gets all sub type definitions defined in a context. + /// + public static IEnumerable GetSubTypeDefinitions (this ITypeDefinition baseType) + { + foreach (var contextType in baseType.Compilation.GetAllTypeDefinitions ()) { + if (contextType.IsDerivedFrom (baseType)) + yield return contextType; + } + } + #endregion } }