<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssemblyUtils.cs" company="Slash Games">
//   Copyright (c) Slash Games. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Slash.Reflection.Utils
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Reflection;

    using Windows.ApplicationModel;
    using Windows.Foundation;
    using Windows.Storage;

    public class AssemblyUtils
    {
        #region Public Methods and Operators

        /// <summary>
        /// Gets all assemblies that are loaded in the current application domain.
        /// </summary>
        /// <returns>All loaded assemblies.</returns>
        public static IEnumerable<Assembly> GetLoadedAssemblies()
        {
            StorageFolder folder = Package.Current.InstalledLocation;

            List<Assembly> assemblies = new List<Assembly>();

            IAsyncOperation<IReadOnlyList<StorageFile>> folderFilesAsync = folder.GetFilesAsync();
            folderFilesAsync.AsTask().Wait();

            foreach (StorageFile file in folderFilesAsync.GetResults())
            {
                if (file.FileType == ".dll" || file.FileType == ".exe")
                {
                    try
                    {
                        var filename = file.Name.Substring(0, file.Name.Length - file.FileType.Length);
                        AssemblyName name = new AssemblyName { Name = filename };
                        Assembly asm = Assembly.Load(name);
                        assemblies.Add(asm);
                    }
                    catch (BadImageFormatException)
                    {
                        /*
                         * TODO(np): Thrown reflecting on C++ executable files for which the C++ compiler
                         * stripped the relocation addresses (such as Unity dlls):
                         * http://msdn.microsoft.com/en-us/library/x4cw969y(v=vs.110).aspx
                         */
                    }
                }
            }

            return assemblies;
        }

        #endregion
    }
}<commit_msg>ADDED: Reflection - Caching list of loaded assemblies on Windows RT.<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssemblyUtils.cs" company="Slash Games">
//   Copyright (c) Slash Games. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Slash.Reflection.Utils
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;

    using Windows.ApplicationModel;
    using Windows.Foundation;
    using Windows.Storage;

    public class AssemblyUtils
    {
        #region Static Fields

        /// <summary>
        ///   Cached list of loaded assemblies.
        /// </summary>
        private static List<Assembly> loadedAssemblies;

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   Gets all assemblies that are loaded in the current application domain.
        /// </summary>
        /// <returns>All loaded assemblies.</returns>
        public static IEnumerable<Assembly> GetLoadedAssemblies()
        {
            // Check if cached.
            if (loadedAssemblies != null)
            {
                return loadedAssemblies;
            }

            // Find assemblies.
            StorageFolder folder = Package.Current.InstalledLocation;

            loadedAssemblies = new List<Assembly>();

            IAsyncOperation<IReadOnlyList<StorageFile>> folderFilesAsync = folder.GetFilesAsync();
            folderFilesAsync.AsTask().Wait();

            foreach (StorageFile file in folderFilesAsync.GetResults())
            {
                if (file.FileType == ".dll" || file.FileType == ".exe")
                {
                    try
                    {
                        var filename = file.Name.Substring(0, file.Name.Length - file.FileType.Length);
                        AssemblyName name = new AssemblyName { Name = filename };
                        Assembly asm = Assembly.Load(name);
                        loadedAssemblies.Add(asm);
                    }
                    catch (BadImageFormatException)
                    {
                        /*
                         * TODO(np): Thrown reflecting on C++ executable files for which the C++ compiler
                         * stripped the relocation addresses (such as Unity dlls):
                         * http://msdn.microsoft.com/en-us/library/x4cw969y(v=vs.110).aspx
                         */
                    }
                }
            }

            return loadedAssemblies;
        }

        #endregion
    }
}
{'fraction_non_alphanumeric': 0.17661003555906757, 'fraction_numerical': 0.0031608060055314103, 'mean_word_length': 1.175762784701332, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6743729', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1042, 'n_words': 271}