![](/img/trans.png)
[英]How can I get a class that takes generic type, to call a method from an instance of that type?
[英]How can I get the class type from inside a generic?
我有以下内容:
public void Delete<T, V>(T item, V repo)
where T : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
where V : IAzureTable<T>
{
try
{
repo.Delete(item);
}
catch (Exception ex)
{
_ex.Errors.Add("", "Error when deleting");
throw _ex;
}
}
我想要做的是让错误消息返回“删除帐户时出错”或“删除内容时出错”。 帐户和内容是类名(T)。 如何获取类的实际名称并附加到错误字符串?
typeof(T).FullName
要么
typeof(T).Name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.