开发者

enum-like data structuring or alternatives

I have a design issue which has proven to bee too much for my current design skills. I hope my request is not too trivial or too stupid for the incredibly skilled people I saw in these forums over time.

Basically, this is what I need: to be able to reference a specific class instantiation by means of another class static or constant declaration (hope it makes as much sense to you as it does to me, hah). The 'enum' behavior would be particularly useful for its 'ease of access' and for its standard methods.

//simple class with a constructor
public class myclass {
  int myint = 0;
  string mystring = "";

  public myclass(int localint, string localstring) {
    myint = localint;
    mystring = localstring;

  }
}

//the core of the issue.
public enum myenum : myclass {
  enum1 = new myclass(9,"abr"),
  enum2 = new myclass(99,"acad"),
  enum3 = new myclass(999,"abra")
}

So that el开发者_JAVA百科sewhere, when I need 'abra', instead of manually instantiating it, and having countless duplicates all over the code, I just

myenum mylocalenum;
mylocalenum = enum3; //no mistake, the underlying class variables are predefined

The purpose is to have a selectable, pre-set 'myenum' which basically encapsulates another data structure which I predefine in the declaration phase.

This is because I have several data pre-sets by design, and I need to interact with them as with an enum (get their number, their descriptions, and basically associate them with predefined values).

If you have a solution, or even a resembling alternative, please let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜