Is there a way to reference the class (i.e. Type
) that inherits a abstract class?
class abstract Monster
{
string Weakness { get; }
string Vice { get; }
Type WhatIAm
{
get { /* somehow return the Vampire type here? */ }
}
}
class Vampire : Monster
{
string Weakness { get { return "sunlight"; }
string Vice { get { return "drinks blood"; } }
}
//somewhere else in code...
Vampire dracula = new Vampire();
Type t = dracula.WhatIAm; // t = Vampire
For those who were curious... what I'm doing: I want to know when my website was last published. .GetExecutingAssembly
worked perfectly until I took the dll out of my solution. After that, the BuildDate
was always the last build date of the utility dll, not the website's dll.
namespace Web.BaseObjects
{
public abstract class Global : HttpApplication
{
/// <summary>
/// Gets the last build date of the website
/// </summary>
/// <remarks>This is the last write time of the website</remarks>
/// <returns></returns>
public DateTime BuildDate
{
get
{
// OLD (was also static)
//return File.GetLastWriteTime(
// System.Reflection.Assembly.GetExecutingAssembly.Location);
return File.GetLastWriteTime(
System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
}
}
}
}