vendredi 11 octobre 2019

How to create generic class accepts multiple types C#

I have two classes:

LinkedEntityProvider<TObj, TRes> and HistValidator<TObj>.

In the second you need to create an instance of the first.

PropertyInfo[] props = typeof(TObj).GetProperties();

foreach (PropertyInfo prop in props)
{
    var sourceAttrs = prop.GetCustomAttribute<Reference>();

    if (sourceAttrs != null)
    {
        Type entityType = sourceAttrs.ReferenceType;

        //Here i need to create LinkedEntityProvider<TObj, TRes> and use type entityType like TRes
    }
}





Aucun commentaire:

Enregistrer un commentaire