vendredi 25 février 2022

error "does not contain a definition for 'getProperty'" when trying to set property of generic typed object

void myFunc<M>()
{
    dynamic uploadReq = (M)Activator.CreateInstance(typeof(M));
    uploadReq.getProperty("Credentials").SetValue(null);
}

I have a function where I supply a type, an object of this type is created, and then a property on the object is set to null. I get an error

MyCustomType does not contain a definition for 'getProperty'

How can I fix this?





Aucun commentaire:

Enregistrer un commentaire