简体   繁体   中英

How can I get the class type from inside a generic?

I have the following:

    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;
        }
    }

What I would like to do is to have the error message return "Error when deleting Account" or "Error when deleting Content". Account and Content are the class names (T). How can I get the actual name of the class and append to the error string?

typeof(T).FullName

要么

typeof(T).Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM