[英]How to pass type as a parameter to Generic return object
I have a method Handle which needs to return a generic type GetCmdResult. 我有一个方法Handle,它需要返回通用类型GetCmdResult。 Now, the type is a parameter being sent.
现在,类型是要发送的参数。 But if I write "return new GetCmdResult" or "new PSDto()", it throws a compile time error.
但是,如果我编写“ return new GetCmdResult”或“ new PSDto()”,则会引发编译时错误。 How can we pass the Type to the generics?
我们如何将类型传递给泛型?
public class GetCmdResult<T> : CR
{
public PSDto<T> PS{ get; set; }
}
public CR Handle(Type type)
{
return new GetCmdResult<type>
{
PS= new PSDto<type>()
};
}
Can use a generic parameter on this method. 可以在此方法上使用通用参数。
public CR Handle<T>(
{
return new GetCmdResult<T>
{
PS= new PSDto<T>()
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.