如何在函数<ti,t =“”>(TI项目)中向T发送未知类型,其中T:class?</ti,>

时间:2014-10-02 15:13:03

标签: c# templates reflection types .net-3.5

我处在以下功能中:

CreateSomething<TI>(TI inputInterface)
{
    Type unknownType = SettingsSystem.GetTypeBasedOnInterface(inputInterface);
    object otherInformation = SomeClass.GetInformation();
    return base.CreateSomething<TI, T>(inputInterface, otherInformation);
}

,其中

base.CreateSomething

returnObject CreateSomething<TI, T>(TI interface, object otherInformation = null)
    where TI : class
    where T : class
{
    return externalDll.DoStuff<T>(interface);
}

我需要的是一种传递类型为unknownType的类的方法,如下所示:

return base.CreateSomething<TI, unknownType>(inputInterface, otherInformation);

而不是像这样的东西

if(version == v1)
    return base.CreateSomething<TI, MyClassV1>(inputInterface, otherInformation);
if(version == v2)
    return base.CreateSomething<TI, MyClassV2>(inputInterface, otherInformation);

0 个答案:

没有答案