mardi 24 mars 2020

How to pass an argument by reference using Reflection

How do I call a method that accepts a parameter by reference? (using the ref keyword). JsonConverter<T> defines the following method:

public abstract T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options);

And I hold a derived type but have the generic parameter as a Type object only. This doesn't compile:

converter.GetType().GetMethod("Read").Invoke(ref reader, type, options);




Aucun commentaire:

Enregistrer un commentaire