使用.Net 的FileHelper库,我可以以某种方式跳过源文件中的多个列吗?
根据文档和示例,我必须为所有列添加字段.唉,我有一个excel表,有216列可以导入,只需要13个.
我想测试不正确的对象引用并编写一个总是失败的测试.我将测试简化为以下行为:
[Test]
public void ScopesAreNotLeaking()
{
WeakReference weakRef;
Stub scope = null;
using (scope = new Stub())
{
weakRef = new WeakReference(scope);
}
scope = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.That(weakRef.Target, Is.Null);
}
Run Code Online (Sandbox Code Playgroud)
然而,该测试在不使用的情况下执行相同的操作:
[Test]
public void ScopesAreNotLeaking()
{
WeakReference weakRef;
Stub scope = new Stub();
weakRef = new WeakReference(scope);
scope = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.That(weakRef.Target, Is.Null);
}
Run Code Online (Sandbox Code Playgroud)
使用的存根类很简单:
class Stub : IDisposable
{
public void Dispose() {}
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下这种行为,或者 - 甚至更好 - 有一个想法,如何确保对象被垃圾收集?
PS:如果之前有过类似的问题,请耐心等待.我只检查了标题中使用的那些问题.