Есть ли способ сослаться на класс (т.е. Type
), который наследует абстрактный класс?
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
Для тех, кому было любопытно ... что я делаю: я хочу знать, когда мой сайт был в последний раз опубликован. .GetExecutingAssembly
работал отлично, пока я не взял dll из своего решения. После этого BuildDate
всегда была последней датой сборки утилиты dll, а не 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);
}
}
}
}