/// <summary> /// Constructor /// </summary> /// <param name="AspectLocation">Aspect DLL location (optional)</param> /// <param name="AssemblyDirectory">Directory to save the generated types (optional)</param> /// <param name="AssemblyName">Assembly name to save the generated types as (optional)</param> /// <param name="RegenerateAssembly">Should this assembly be regenerated if found? (optional)</param> public AOPManager(string AspectLocation = "", string AssemblyDirectory = "", string AssemblyName = "Aspects", bool RegenerateAssembly = false) { this.AssemblyDirectory = AssemblyDirectory; this.AssemblyName = AssemblyName; this.RegenerateAssembly = RegenerateAssembly; if (!string.IsNullOrEmpty(AspectLocation)) { if (AspectLocation.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase)) { Aspects.AddRange(new AssemblyName(AspectLocation).Load().GetObjects <IAspect>()); } else if (new DirectoryInfo(AspectLocation).Exists) { Aspects.AddRange(new DirectoryInfo(AspectLocation).GetObjects <IAspect>()); } else { Aspects.AddRange(new AssemblyName(AspectLocation).Load().GetObjects <IAspect>()); } } if (AssemblyBuilder != null) { return; } if (string.IsNullOrEmpty(AssemblyDirectory) || !new FileInfo(AssemblyDirectory + AssemblyName + ".dll").Exists || RegenerateAssembly) { AssemblyBuilder = new Utilities.Reflection.Emit.Assembly(AssemblyName, AssemblyDirectory); } else { new AssemblyName(AssemblyDirectory + AssemblyName + ".dll").Load() .GetTypes() .ForEach(x => Classes.Add(x.BaseType, x)); } }