Calling derived class method

G

Guest

I defined a property in a base class that will under certain condition return
its own value, but sometimes needs to pass the implementation to the derived
class. Now the proble is that in the method I need a name of the derived
class to perform some database query. It looks like this:

public abstract class MyAbstractClass
{
protected MyAbstractClass()
{
}

// This implementation will be forced with a derived class
public override string FindInDerivedClass
{
get;
}

public string FindSomething()
{

string found = CalculateSomething(<<<NameOfTheDerivedClass>>>);

if (found != null)
return found;
else
return FindInDerivedClass;
}

}


So the question is, as I need the name of the class that will inherit this
base clase, how do I get the value for the above <<<NameOfTheDerivedClass>>>?

Thank you.
 
M

Mattias Sjögren

public override string FindInDerivedClass
^^^^^^^^
I assume you mean abstract.

So the question is, as I need the name of the class that will inherit this
base clase, how do I get the value for the above <<<NameOfTheDerivedClass>>>?

this.GetType().Name should give you the name of the actual type of
your object.


Mattias
 
G

Guest

Thanks. I will try that out.

Mattias Sjögren said:
^^^^^^^^
I assume you mean abstract.



this.GetType().Name should give you the name of the actual type of
your object.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top