I have a problem with a typed method in C #. I want to call an inherited method of an object. This method calls a static method with the "this" parameter. The parameter of the static method is general. Now I want the generic type of this parameter to be the type of the first object. But a parameter is always a type of abstract class.
Here is an example:
abstract class AbstractClass
{
bool update()
{
Connection.Update(this);
}
}
class Entity : AbstractClass
{
}
class Connection
{
public static void Update<T>(T obj)
{
someMethod<T>()
}
}
If I try to do:
Entity foo = new Entity();
foo.update();
Connection.Update will look like this in the debugger:
public static void Update<AbstractClass>(AbstractClass obj)
{
someMethod<AbstractClass>()
}
But I want this:
public static void Update<Entity>(Entity obj)
{
someMethod<Entity>()
}
Is there a possibility of something like
someMethod<typeof(obj)>()
or anything else to solve my problem?
Jan s source
share