嗨我有一个从抽象类Item派生的对象new Sword()。我可以以某种方式使用字符串属性Name或this.GetType()。ToString()作为标识符来引用另一个类的常量对象(静态)。我想提到一个提供的位图图像 来自另一个静态类的System.Drawing.Bitmap对象。这是我的代码:
基本上:
//WORKS
return HeroesPrototype.mapConsts.Bitmaps.sword;
//NOT WORKS
string Name="sword";
return HeroesPrototype.mapConsts.Bitmaps.<string Name>;
//More in details:
abstract class Item:Drawable//class Item will serve as parent for all items(axe,sword, staff etc.) in this case new Sword()
{
public string Name { get; set; }//property that I wish to use for identifier
Bitmap Drawable.GetSprite()//method from Drawable interface that I wish to inherit for all types of item
{
return HeroesPrototype.mapConsts.Bitmaps.<string Name>;//Name="sword" is my object identifier
}
}
namespace HeroesPrototype.mapConsts
{
public static class Bitmaps
{
public static System.Drawing.Bitmap castle = new System.Drawing.Bitmap(Bitmap.FromFile(@"..\..\sprites\mapobj\sword.png"));
}
}