Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Changing type forwards to be looped from the contract assembly instea…
Browse files Browse the repository at this point in the history
…d of the seedtype.
  • Loading branch information
joperezr committed Oct 8, 2015
1 parent bbce670 commit 1c92e35
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/GenFacades/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public Assembly GenerateFacade(IAssembly contractAssembly, IAssemblyReference se
continue;
}

AddTypeForward(assembly, seedType);
AddTypeForward(assembly, seedType, contractAssembly);
}

if (error)
Expand Down Expand Up @@ -475,7 +475,7 @@ private static void TraceDuplicateSeedTypeError(string docId, IReadOnlyList<INam
}
}

private void AddTypeForward(Assembly assembly, INamedTypeDefinition seedType)
private void AddTypeForward(Assembly assembly, INamedTypeDefinition seedType, IAssembly contractAssembly)
{
var alias = new NamespaceAliasForType();
alias.AliasedType = ConvertDefinitionToReferenceIfTypeIsNested(seedType, _seedHost);
Expand All @@ -485,13 +485,21 @@ private void AddTypeForward(Assembly assembly, INamedTypeDefinition seedType)
assembly.ExportedTypes = new List<IAliasForType>();
assembly.ExportedTypes.Add(alias);

// Recursively add forwarders only for the nested types that are accessible outside of the assembly.
INamedTypeDefinition contractType = contractAssembly.GetAllTypes().Where(t => t.FullName() == seedType.FullName()).FirstOrDefault();
if (contractType == null)
throw new Exception("Type was not found in the contract.");

// Recursively add forwarders for all the nested types specified in the contract assembly.
// NOTE: Some design-time tools can resolve forwarded nested types with only the top-level forwarder,
// but the runtime currently throws a TypeLoadException without explicit forwarders for the nested
// types.
foreach (var nestedType in seedType.NestedTypes.OrderBy(t => t.Name.Value))
if (nestedType.IsVisibleOutsideAssembly())
AddTypeForward(assembly, nestedType);
foreach (var nestedType in contractType.NestedTypes.OrderBy(t => t.Name.Value))
{
var seedNestedType = seedType.NestedTypes.Where(nt => nt.Name.Value == nestedType.Name.Value).FirstOrDefault();
if (seedNestedType == null)
throw new Exception("Nested type found in the contract, but not on the seedType.");
AddTypeForward(assembly, seedNestedType, contractAssembly);
}
}

private void AddWin32VersionResource(string contractLocation, Assembly facade)
Expand Down

0 comments on commit 1c92e35

Please sign in to comment.