| 32 | using RazorTemplates.Core; |
| 33 | |
| 34 | public class Reflector |
| 35 | { |
| 36 | static string BaseWindMDDir = null; |
| 37 | static Reflector() |
| 38 | { |
| 39 | AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, eventArgs) => Assembly.ReflectionOnlyLoad(eventArgs.Name); |
| 40 | WindowsRuntimeMetadata.ReflectionOnlyNamespaceResolve += (sender, eventArgs) => |
| 41 | { |
| 42 | |
| 43 | string path = |
| 44 | WindowsRuntimeMetadata.ResolveNamespace(eventArgs.NamespaceName, Enumerable.Empty<string>()) |
| 45 | .FirstOrDefault(); |
| 46 | |
| 47 | if (path == null) return; |
| 48 | |
| 49 | if (!String.IsNullOrEmpty(BaseWindMDDir)) |
| 50 | { |
| 51 | var newPath = Path.Combine(BaseWindMDDir, System.IO.Path.GetFileName(path)); |
| 52 | eventArgs.ResolvedAssemblies.Add(Assembly.ReflectionOnlyLoadFrom(newPath)); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | eventArgs.ResolvedAssemblies.Add(Assembly.ReflectionOnlyLoadFrom(path)); |
| 57 | } |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | public static IEnumerable<string> GetNamespaces(string winmdFile, string baseWinMDDir) |
| 62 | { |
| 63 | BaseWindMDDir = baseWinMDDir; |
| 64 | var assembly = Assembly.ReflectionOnlyLoadFrom(winmdFile); |
| 65 | if (!assembly.FullName.Contains("WindowsRuntime")) |
| 66 | { |
| 67 | return new string[0]; |
| 68 | } |
| 69 | |
| 70 | var namespaces = from t in assembly.ExportedTypes select t.Namespace; |
| 71 | |
| 72 | return namespaces.Distinct(); |
| 73 | } |
| 74 | |
| 75 | public static dynamic GenerateModel(string winmdFile, string winRTNamespace, string baseWinMDDir) |
| 76 | { |
| 77 | BaseWindMDDir = baseWinMDDir; |
| 78 | var assembly = Assembly.ReflectionOnlyLoadFrom(winmdFile); |
| 79 | if (!assembly.FullName.Contains("WindowsRuntime")) |
| 80 | { |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | return GenerateModel(assembly, winRTNamespace); |
| 85 | } |
| 86 | |
| 87 | public static IList<TypeInfo> GetHiddenTypesForNamespace(Assembly assembly, string winRTNamespace) |
| 88 | { |
| 89 | // namespace specific handlers: |
| 90 | // Windows.Foundation.Uri is exposed in c++ while in c# System.Uri is used. Retreive the definition of Windows.Foundation.Uri specifically. |
| 91 | if (winRTNamespace.Equals("Windows.Foundation")) |
nothing calls this directly
no outgoing calls
no test coverage detected