From 81afa9a0c1b3c0ee10b0dd0a838997244c451626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20LARIVIERE?= Date: Mon, 12 Nov 2018 19:35:19 +0100 Subject: [PATCH] Generator - Add support for types with base type in another assembly --- tools/Generator/Program.fs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/Generator/Program.fs b/tools/Generator/Program.fs index 29531f212..72d03e013 100644 --- a/tools/Generator/Program.fs +++ b/tools/Generator/Program.fs @@ -97,6 +97,30 @@ type TextWriter with member this.printf fmt = fprintf this fmt member this.printfn fmt = fprintfn this fmt +type RegistrableResolver() = + inherit BaseAssemblyResolver() + + let cache = Dictionary() + + override this.Resolve(name) = + match cache.TryGetValue(name.FullName) with + | true, assembly -> assembly + | false, _ -> + let assembly = base.Resolve(name) + cache.[name.FullName] <- assembly + assembly + + member this.RegisterAssembly(assembly: AssemblyDefinition): unit = + match cache.ContainsKey(assembly.Name.FullName) with + | true -> () + | false -> + cache.[assembly.Name.FullName] <- assembly + + member this.Dispose(disposing) = + cache.Values |> Seq.iter (fun asm -> asm.Dispose()) + cache.Clear() + base.Dispose() + let (|NotNullOrWhitespace|_|) (s:string) = if String.IsNullOrWhiteSpace s then None else Some s let ResolveType(this: Bindings, name: string) = @@ -579,12 +603,16 @@ let BindTypes (bindings: Bindings, resolutions: IDictionary] @@ -598,7 +626,8 @@ let Main(args: string[]) = let bindings = JsonConvert.DeserializeObject (File.ReadAllText (bindingsPath)) - bindings.AssemblyDefinitions <- bindings.Assemblies.Select(LoadAssembly).ToList() + let resolver = new RegistrableResolver() + bindings.AssemblyDefinitions <- bindings.Assemblies.Select(LoadAssembly resolver).ToList() let resolutions = [ for x in bindings.Types do