Samantha J T Star
Samantha J T Star

Reputation: 32848

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?

Upvotes: 3

Views: 68

Answers (1)

ryudice
ryudice

Reputation: 37466

typeof(T).FullName

or

typeof(T).Name

Upvotes: 7

Related Questions