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

Commit

Permalink
Adding special case for ExportedTypes, since they should be copied wi…
Browse files Browse the repository at this point in the history
…th all of their nested types always
  • Loading branch information
joperezr committed Oct 8, 2015
1 parent 1c92e35 commit fe9b4f1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/GenFacades/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,21 +485,24 @@ private void AddTypeForward(Assembly assembly, INamedTypeDefinition seedType, IA
assembly.ExportedTypes = new List<IAliasForType>();
assembly.ExportedTypes.Add(alias);

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.
// Recursively add forwarders for nested types.
// 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 contractType.NestedTypes.OrderBy(t => t.Name.Value))
INamedTypeDefinition contractType = contractAssembly.GetAllTypes().Where(t => t.FullName() == seedType.FullName()).FirstOrDefault();
if (contractType != null) // Only add forwarders for the nested types on the contract
{
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);
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);
}
}
else // Add all the nested types for ExportedTypes.
foreach (var nestedType in seedType.NestedTypes.OrderBy(t => t.Name.Value))
AddTypeForward(assembly, nestedType, contractAssembly);
}

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

0 comments on commit fe9b4f1

Please sign in to comment.