jeudi 2 juin 2016

Getting a generic method with reflection

I am trying to get the method ExecuteQuery from Azure's CloudTable. There are four methods by this name.

public virtual IEnumerable<TElement> ExecuteQuery<TElement>(TableQuery<TElement> query, TableRequestOptions requestOptions = null, OperationContext operationContext = null) where TElement : ITableEntity, new();
public virtual IEnumerable<DynamicTableEntity> ExecuteQuery(TableQuery query, TableRequestOptions requestOptions = null, OperationContext operationContext = null);
public virtual IEnumerable<TResult> ExecuteQuery<TElement, TResult>(TableQuery<TElement> query, EntityResolver<TResult> resolver, TableRequestOptions requestOptions = null, OperationContext operationContext = null) where TElement : ITableEntity, new();
public virtual IEnumerable<TResult> ExecuteQuery<TResult>(TableQuery query, EntityResolver<TResult> resolver, TableRequestOptions requestOptions = null, OperationContext operationContext = null);

The one I am trying to get is the first one. And I am using the following code.

var testQuery = new TableQuery<TestEntity>();
var methodInfo = typeof(CloudTable).GetMethod("ExecuteQuery", new[] { testQuery.GetType(), typeof(TableRequestOptions), typeof(OperationContext) });

However methodInfo results in as null. Why can't it find the specified method? As I look returning null means there is no such method. By the way TestEntity is a dummy class inheriting from TableEntity and in turn implementing the interface ITableEntity. Therefore the conditions are met for the specified method.

I am going to use this method on a class which is created by reflection at run time. Therefore I am trying to get the method this way.





Aucun commentaire:

Enregistrer un commentaire