Click here to Skip to main content
15,895,142 members
Articles / Programming Languages / C#

Serializable Extra Types for .NET 4

Rate me:
Please Sign up or sign in to vote.
4.85/5 (9 votes)
25 May 2011GPL33 min read 54K   335   13  
Serialization for Rapid Application Development.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Compilation;

namespace Net.AMightyOak
{
    internal class HttpAssemblyLocator
    {
        private IEnumerable<Assembly> AllAssemblies = null;
        private IEnumerable<Assembly> BinFolderAssemblies = null;

        internal HttpAssemblyLocator()
        {
            AllAssemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>();

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

            string binFolder = HttpRuntime.AppDomainAppPath + "bin\\";
            IList<string> dllFiles = Directory.GetFiles(binFolder, "*.dll",
                SearchOption.TopDirectoryOnly).ToList();

            foreach (string dllFile in dllFiles)
            {
                AssemblyName assemblyName = AssemblyName.GetAssemblyName(dllFile);

                Assembly locatedAssembly = AllAssemblies.FirstOrDefault(a =>
                    AssemblyName.ReferenceMatchesDefinition(a.GetName(), assemblyName));

                if (locatedAssembly != null)
                {
                    binFolderAssemblies.Add(locatedAssembly);
                }
            }

            BinFolderAssemblies = binFolderAssemblies;
        }

        internal IEnumerable<Assembly> GetAssemblies()
        {
            return AllAssemblies;
        }

        internal IEnumerable<Assembly> GetBinFolderAssemblies()
        {
            return BinFolderAssemblies;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect Stackify
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions