Now before I start: I know that there are many questions like this already that have been answered.
Ive tried the lot of them and they just dont ssem to work for me and Im not quite sure what im doing wrong. My running theory is, that what the thing Im trying to do is rather niche and also very “hey you shouldnt be doing it like this at all”, and all the answers Ive found have aged a good bit. but it has now really gotten my interest and im kinda locked in on finding out how to do it.
With all of this out of the way here is what I have:
public static class Extensions
{
public static void AttemptToCallMethod<T>(DataTableFilter searchParameters, IEnumerable<T> aList)
{
IQueryable<T> queriedList = aList.AsQueryable();
//this works
Type sourceType = typeof(T);
//this works
Type columnType = typeof(T).GetProperty(searchParameters.ColumnProperty).PropertyType; //the type in the specific instance is going to be int
//this works
Type searchParameterValueType = searchParameters.ColumnValue.GetType(); //this has a good chance of getting dropped since its always object but I want to keep my options open
object[] parameters = new[] { searchParameters.ColumnValue, searchParameters.ColumnProperty }; //the parameters to be used later on
//var typeOfContext = typeof(Queryable) its gonna be one of the two i assume
var typeOfContext = queriedList.GetType(); // this is the type i will use to get the method
//something isnt right here
var method = typeOfContext.GetMethod("GenericMethodTester"); //this is supposed to get me the Method but both the GetType() and typeof() deliver null
//obviously throws an error since method is null for some reason
var genericMethod = method.MakeGenericMethod(sourceType, searchParameterValueType, columnType);
//never gets this far
genericMethod.Invoke(queriedList, parameters);
//here we have the smaller showcase Version to test around with and to proof that the Types/the amount of types arent the problem
var methodOne = typeOfContext.GetMethod("GenericMethodTesterOne");
var genericMethodOneT = methodOne.MakeGenericMethod(sourceType);
var genericMethodOneObj = methodOne.MakeGenericMethod(searchParameterValueType);
var genericMethodOneCol = methodOne.MakeGenericMethod(columnType);
}
//this is a smaller version for the showcase, since the error message is the same and the error isnt really due to the parameters
public static void GenericMethodTesterOne<TA>(this IQueryable<TA> tarra)
{
}
public static void GenericMethodTester<TA, TB, TC>(this IQueryable<TA> typeA, TB typeB, TC typeC)
{
//the implementation of this is rather unimportant since the call is the problem
}
}
The Problem obviously is that for some reason the GetMehod never gives me any of my Generics.
Now im not gonna include the use case here since I do not think that it is relevant to the error, since the problem is that I cant find the method and that the methods arent even listed when i use the GetMethods()
on typeof()
nor when I ise GetType()
.
So my question is: What am I doing wrong here.
Ive tried
This first
This second
Thist last
and some others in between
Now if you think Ive left out some crucial information regarding your ability to reconstruct this you can tell me imediatly.
The DataTableFilter class is just a string a object and a string, with Property Column being string and ColoumnValue being object