Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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?

like image 477
Samantha J T Star Avatar asked Nov 30 '25 10:11

Samantha J T Star


1 Answers

typeof(T).FullName

or

typeof(T).Name
like image 173
ryudice Avatar answered Dec 02 '25 22:12

ryudice