111,131
社区成员
发帖
与我相关
我的任务
分享 public class MemoryTypeMap
{
private Dictionary<Type, TypeConstructor> _dicType = new Dictionary<Type, TypeConstructor>();
private ITypeMap _typeMapInstance;
private MemoryTypeMap() { }
static MemoryTypeMap()
{
MemoryTypeMap singleton = new MemoryTypeMap();
singleton._dicType.Add(typeof(IWeatherReader), new TypeConstructor(typeof(WeatherReaderImpl), "s"));
}
public TypeConstructor this[Type type]
{
get
{
TypeConstructor constructor;
if(!_dicType.TryGetValue(type,out constructor))
{
return null;
}
else
{
return constructor;
}
}
}
}public class MemoryTypeMap
{
private Dictionary<Type, TypeConstructor> _dicType = new Dictionary<Type, TypeConstructor>();
private ITypeMap _typeMapInstance;
private MemoryTypeMap() { }
static MemoryTypeMap()
{
MemoryTypeMap singleton = new MemoryTypeMap(); //这样是否会导致无限递归?????、????
singleton._dicType.Add(typeof(IWeatherReader), new TypeConstructor(typeof(WeatherReaderImpl), "s"));
}
public TypeConstructor this[Type type]
{
get
{
TypeConstructor constructor;
if(!_dicType.TryGetValue(type,out constructor))
{
return null;
}
else
{
return constructor;
}
}
}
}static MemoryTypeMap()
{
MemoryTypeMap singleton = new MemoryTypeMap();
singleton._dicType.Add(typeof(IWeatherReader), new TypeConstructor(typeof(WeatherReaderImpl), "s"));//这个方法如果是写入文件的话??
}
MemoryTypeMap m = (MemoryTypeMap)Activator.CreateInstance(typeof(MemoryTypeMap), true);