什么是GenericParameterHelper以及它是如何使用的?

Bry*_*son 12 .net

我在VS 2008中对泛型类生成了单元测试,并且在使用泛型类型的所有位置使用了GenericParameterHelper类型.这是一个应该被替换的占位符还是有一些用处?有什么用途?

以下是它生成的一个测试示例:

/// <summary>
///A test for Count
///</summary>
public void CountTestHelper<TKey, TValue>()
{
    ObservableDictionary<TKey, TValue> target = new ObservableDictionary<TKey, TValue>(); // TODO: Initialize to an appropriate value
    int actual;
    actual = target.Count;
    Assert.Inconclusive("Verify the correctness of this test method.");
}

[TestMethod()]
public void CountTest()
{
    CountTestHelper<GenericParameterHelper, GenericParameterHelper>();
}
Run Code Online (Sandbox Code Playgroud)

Cra*_*ntz 8

假设你有一个班级:

public class Foo<T>
{
    public bool DoSomething()
    {
        return false;
    }

    public T DoSomethingElse()
    {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

现在你要测试DoSomething.首先,你必须实例化Foo.你做不到:

var foo = new Foo<T>();
Run Code Online (Sandbox Code Playgroud)

你必须使用真实的类型.但是T不用于该方法,所以它在测试中是噪音.所以你可以这样做:

var foo = new Foo<GenericParameterHelper>();
Run Code Online (Sandbox Code Playgroud)

...或多或少地代表"任何旧类型".