mardi 26 octobre 2021

Finding Generic Type Parameter through reflection [duplicate]

I'm new to Reflection and Im just trying cool little ideas.

I'm trying to see if there is a way to find the type that a property is and pass it through a generic type parameter? If it's not possible that's ok, just would be fun to play around with, even if it's not that efficient

I have the field type, just need to have a way to convert it so it's acceptable by the compiler, unless generic type parameters need to be hard coded.

Here is an example of what I want to do:

foreach(FieldInfo f in typeof(ActivityData).GetFields())
{ 
    Database.GetData</*Do something here?*/>(nReader, "");
}

rtn.ActionID = Database.GetData<int>(nReader, GetAttribute<DBAttribute, ActivityData>(nameof(this.ActionID)).ColumnName);

So the last line is what I want to do, but for each field inside of my object, however, I'm not sure how to get the generic type parameter through reflection, or if its possible at all.





Aucun commentaire:

Enregistrer un commentaire