Skip to content

Commit

Permalink
Merge pull request #153 from qba97/master
Browse files Browse the repository at this point in the history
#132 - fix missing namespaces issue while processing model DLL
  • Loading branch information
mpostol authored Feb 2, 2019
2 parents e032d9a + 250f60f commit 7a67a63
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 0 additions & 1 deletion AdaptiveProgramming/Reflection/Model/AssemblyMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions AdaptiveProgramming/Reflection/Model/TypeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -46,6 +50,7 @@ internal static IEnumerable<TypeMetadata> EmitGenericArguments(IEnumerable<Type>
#endregion

#region private
private static Dictionary<string, TypeMetadata> storedTypes = new Dictionary<string, TypeMetadata>();
//vars
internal string m_typeName;
internal string m_NamespaceName;
Expand Down Expand Up @@ -75,16 +80,19 @@ private TypeMetadata EmitDeclaringType(Type declaringType)
{
if (declaringType == null)
return null;
AddToStoredTypes(declaringType);
return EmitReference(declaringType);
}
private IEnumerable<TypeMetadata> EmitNestedTypes(IEnumerable<Type> nestedTypes)
{
AddToStoredTypes(nestedTypes);
return from _type in nestedTypes
where _type.GetVisible()
select new TypeMetadata(_type);
}
private IEnumerable<TypeMetadata> EmitImplements(IEnumerable<Type> interfaces)
{
AddToStoredTypes(interfaces);
return from currentInterface in interfaces
select EmitReference(currentInterface);
}
Expand Down Expand Up @@ -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<Type> types)
{
foreach (Type type in types)
{
AddToStoredTypes(type);
}
}
#endregion

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(4, ReflectorTestClass.Reflector.Namespaces.Count);
}
[TestMethod]
Expand Down

0 comments on commit 7a67a63

Please sign in to comment.