嗨,我有一个组装问题。装配问题
我有一个程序,谁创建一个类。在那个类中,我使用了我的不同DLL中的一些其他类。在那个DLL类的方法中,我必须使用Assembly类,但是我会参考程序Assembly,并且我不知道该怎么做。
如果(在DLL)我的用户Assembly.GetExecutingAssembly(),或CallingAssembly我总是得到DLL组件:/
的GetEntryAssembly总是做StackOverflow的例外。
在DLL中,我不能与程序有任何连接。
编辑:
DLL
public sealed class MapperSet<T> : MapperSetBase<T>, IMapperSet<T>
{
public MapperSet()
{
_Mapper = GetSpecificMapper();
//if (_mapper == null)
// throw new NullReferenceException();
}
// some methods, not use yet
}
public abstract class MapperSetBase<T> : IQuerySet
{
protected virtual IMapper GetSpecificMapper()
{
Type[] assemblyTypes = Assembly.GetExecutingAssembly().GetTypes();
IMapper mapper = null;
foreach (Type type in assemblyTypes)
{
if (type.GetInterfaces().Any(i => i == typeof(IMapper)))
{
FieldInfo[] fields = type.GetFields();
foreach (FieldInfo field in fields)
{
if (field.FieldType.GetGenericArguments().Count() > 0)
{
Type mapperFieldType = field.FieldType.GetGenericArguments()[0];
if (mapperFieldType == typeof(T))
{
mapper = (IMapper)Activator.CreateInstance(type);
}
}
}
}
}
}
程序代码
public class DB : IMapper
{
public string ConnectionString
{
get { return "TestConnectionString"; }
}
public DBTypes DbType
{
get { return DBTypes.MsSql; }
}
public MapperSet<Person> Persons = new MapperSet<Person>();
public List<int> l1 = new List<int>();
}
在MapperSet有一些方法。当我调用其中的一个时,我必须从IMapper类获得ConnectionString和DbType。
你是否100%确定它正在调用产生堆栈溢出异常的'GetEntryAssembly'?你可以显示你称之为的代码吗? – 2011-04-30 12:08:44
删除[assembly]标签;它用于汇编语言问题。 – 2011-04-30 17:21:26