Here I've mentioned a class from CsvHelper.CsvReader,
public class CsvReader : IReader, IReaderRow, IDisposable
{
....
....
public virtual IEnumerable<T> GetRecords<T>();
public virtual IEnumerable<object> GetRecords(Type type);
}
public class Test
{
....
}
In this, I would like to invoke GetRecords method using reflection in C#,
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
HasHeaderRecord = true,
MissingFieldFound = null,
HeaderValidated = null,
};
CsvHelper.CsvReader csvReader = new CsvHelper.CsvReader(binaryData), config);
//direct all
var result = csvReader.GetRecords<Test>();
now, I need to call this GetRecords using reflection. So, I've tried as below,
MethodInfo methodInfo = csvReader.GetType().GetMethod("GetRecords");
while calling this methodInfo, it throws "ambiguous match found".
Kindly help me on this, how to resolve this issue.
EDIT:
Type genericType = typeof(Test);//it will be dynamic to pass
MethodInfo methodInfo = csvReader.GetType().GetMethod("GetRecords", new[] { typeof(IEnumerable<object>) });
var result = await methodInfo.InvokeAsync(genericType, new[] { csvReader });
So that, I'm unable to Invoke it since methodInfo getting as null.