diff --git a/AdaptiveProgramming/Reflection/Model/AssemblyMetadata.cs b/AdaptiveProgramming/Reflection/Model/AssemblyMetadata.cs index fc7462af..93dd4de7 100644 --- a/AdaptiveProgramming/Reflection/Model/AssemblyMetadata.cs +++ b/AdaptiveProgramming/Reflection/Model/AssemblyMetadata.cs @@ -13,7 +13,6 @@ internal AssemblyMetadata(Assembly assembly) { m_Name = assembly.ManifestModule.Name; m_Namespaces = from Type _type in assembly.GetTypes() - where _type.GetVisible() group _type by _type.GetNamespace() into _group orderby _group.Key select new NamespaceMetadata(_group.Key, _group); diff --git a/AdaptiveProgramming/Reflection/Model/TypeMetadata.cs b/AdaptiveProgramming/Reflection/Model/TypeMetadata.cs index 8f04019c..3abbd92c 100644 --- a/AdaptiveProgramming/Reflection/Model/TypeMetadata.cs +++ b/AdaptiveProgramming/Reflection/Model/TypeMetadata.cs @@ -12,6 +12,10 @@ internal class TypeMetadata #region constructors internal TypeMetadata(Type type) { + if (!storedTypes.ContainsKey(type.Name)) + { + storedTypes.Add(type.Name, this); + } m_typeName = type.Name; m_DeclaringType = EmitDeclaringType(type.DeclaringType); m_Constructors = MethodMetadata.EmitMethods(type.GetConstructors()); @@ -46,6 +50,7 @@ internal static IEnumerable EmitGenericArguments(IEnumerable #endregion #region private + private static Dictionary storedTypes = new Dictionary(); //vars internal string m_typeName; internal string m_NamespaceName; @@ -75,16 +80,19 @@ private TypeMetadata EmitDeclaringType(Type declaringType) { if (declaringType == null) return null; + AddToStoredTypes(declaringType); return EmitReference(declaringType); } private IEnumerable EmitNestedTypes(IEnumerable nestedTypes) { + AddToStoredTypes(nestedTypes); return from _type in nestedTypes where _type.GetVisible() select new TypeMetadata(_type); } private IEnumerable EmitImplements(IEnumerable interfaces) { + AddToStoredTypes(interfaces); return from currentInterface in interfaces select EmitReference(currentInterface); } @@ -120,8 +128,26 @@ private static TypeMetadata EmitExtends(Type baseType) { if (baseType == null || baseType == typeof(Object) || baseType == typeof(ValueType) || baseType == typeof(Enum)) return null; + AddToStoredTypes(baseType); return EmitReference(baseType); } + + private static void AddToStoredTypes(Type type) + { + if (!storedTypes.ContainsKey(type.Name)) + { + // TypeMetadata object is added to dictionary when invoking its constructor + new TypeMetadata(type); + } + } + + private static void AddToStoredTypes(IEnumerable types) + { + foreach (Type type in types) + { + AddToStoredTypes(type); + } + } #endregion } diff --git a/AdaptiveProgramming/ReflectionUnitTest/ReflectorUnitTest.cs b/AdaptiveProgramming/ReflectionUnitTest/ReflectorUnitTest.cs index 4f4eaa2d..24dab204 100644 --- a/AdaptiveProgramming/ReflectionUnitTest/ReflectorUnitTest.cs +++ b/AdaptiveProgramming/ReflectionUnitTest/ReflectorUnitTest.cs @@ -27,7 +27,6 @@ public void ReflectorConstructorTest() Assert.IsTrue(_fileInfo.Exists); Assert.IsNotNull(ReflectorTestClass.Reflector); Assert.IsNotNull(ReflectorTestClass.Reflector.MyNamespace); - Assert.Inconclusive("Nor all types are processed - test fails."); Assert.AreEqual(4, ReflectorTestClass.Reflector.Namespaces.Count); } [TestMethod]