示例#1
0
 public ObjectFactory(string assemblyname, AssemblyPathType pathtype, string assemblypath, string classname, object[] constructorparameters)
 {
     this.AssemblyName          = assemblyname;
     this.PathType              = pathtype;
     this.AssemblyPath          = assemblypath;
     this.ClassName             = classname;
     this.ConstructorParameters = constructorparameters;
 }
示例#2
0
        public static IEnumerable <T> LoadAssemblyInstances <T>(string assemblyFilename, AssemblyPathType assemblyPathType = AssemblyPathType.RelativePath)
        {
            if (assemblyPathType == AssemblyPathType.RelativePath)
            {
                var basePath = AppDomain.CurrentDomain.RelativeSearchPath != null ? AppDomain.CurrentDomain.RelativeSearchPath : AppDomain.CurrentDomain.BaseDirectory;
                assemblyFilename = basePath.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar + assemblyFilename;
            }

            AssemblyName an   = AssemblyName.GetAssemblyName(assemblyFilename);
            var          hmm3 = Assembly.Load(an);

            Type[] iLoadTypes = (from t in hmm3.GetExportedTypes()
                                 where !t.IsInterface && !t.IsAbstract
                                 where typeof(T).IsAssignableFrom(t)
                                 select t).ToArray();

            return(iLoadTypes.Select(t => (T)Activator.CreateInstance(t)));
        }
示例#3
0
 public ObjectFactory(string assemblyname, AssemblyPathType pathtype, string classname)
 {
     this.AssemblyName = assemblyname;
     this.PathType     = pathtype;
     this.ClassName    = classname;
 }