summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatformServices.cs
blob: 37d2d4fb9b046ea050ae9c77f3f0d31a4228e058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.UI.Core;

namespace Xamarin.Forms.Platform.WinRT
{
	internal class WindowsPhonePlatformServices
		: WindowsBasePlatformServices
	{
		public WindowsPhonePlatformServices (CoreDispatcher dispatcher)
			: base (dispatcher)
		{
		}

		public override Assembly[] GetAssemblies()
		{
			var files = Package.Current.InstalledLocation.GetFilesAsync().AsTask().Result;
			
			List<Assembly> assemblies = new List<Assembly> (files.Count);
			for (int i = 0; i < files.Count; i++) {
				StorageFile file = files[i];
				if (file.Name.Length < 3)
					continue;

				string extension = file.Name.Substring (file.Name.Length - 3, 3).ToLower();
				if (extension != "dll" && extension != "exe")
					continue;

				try {
					Assembly assembly = Assembly.Load (new AssemblyName { Name = Path.GetFileNameWithoutExtension (file.Name) });
					assemblies.Add (assembly);
				} catch (IOException) {
				} catch (BadImageFormatException) {
				}
			}

			return assemblies.ToArray();
		}
	}
}