using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.IO; namespace StackedGeometryDesigner { class AttributeReflector { private List<AttributeReflectionItem> mReflectionItems = new List<AttributeReflectionItem>(); public List<AttributeReflectionItem> ReflectionItems { get { return mReflectionItems; } set { mReflectionItems = value; } } public void Reflect(string path, SearchOption searchOption) { string[] files = Directory.GetFiles(path, "*.dll", searchOption); List<Assembly> assemblies = new List<Assembly>(); foreach (string f in files) { try { Assembly asm = Assembly.LoadFile(f); if (asm != null) { assemblies.Add(asm); } } catch{} } Reflect(assemblies); } public void Reflect(ICollection<Assembly> assemblies){ foreach (Assembly asm in assemblies) { Reflect(asm); } } public void Reflect(Assembly assembly) { List<AttributeReflectionItem> assemblyReflectionItems = new List<AttributeReflectionItem>(); foreach (AttributeReflectionItem ri in mReflectionItems) { if (Attribute.GetCustomAttribute(assembly, ri.AssemblyAttribute) != null) { assemblyReflectionItems.Add(ri); } } if (mReflectionItems.Count > 0) { foreach (Type t in assembly.GetTypes()) { foreach (AttributeReflectionItem ri in mReflectionItems) { if (Attribute.GetCustomAttribute(t, ri.ClassAttribute) != null) { ri.List.Add(Activator.CreateInstance(t, null)); } } } } } } }
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.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)