wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> using enum or old-fashion way in C#
(Message started by: puzzlecracker on Sep 28th, 2008, 3:51pm)

Title: using enum or old-fashion way in C#
Post by puzzlecracker on Sep 28th, 2008, 3:51pm
I am porting old java code to csharp and now facing a stumbling block. Before advent of enum in Java, developers used enum-like structures, shown below. However, AFAIK, CSharp isn't lacking this particular feature, and  I don't want to  port it in an old way. Here is the code below (in java ) that I want to approximate in C#. Note that I have lots of  alike classes.


Code:
public class Derived extends Base {

 public static final int FOO_VAL = 0 ;
 public static final int BAR_VAL = 1 ;
;

 public static final Derived  FOO  =  new Derived(FOO_VAL, "FOO");

 public static final Derived BAR    =  new Derived(BAR_VAL, "BAR");

 private  Derived(int aValue) {

       super(aValue);
 }

 private  Derived(int aValue, String aString) {

       super(aValue,  aString);
 }

 public  static Derived getType (int aValue) {

       if ( aValue == FOO_VAL ) return FOO;
       if ( aValue == BAR_VAL ) return BAR;

       return NEW;
 }
//Getting type accross the wire
 public  static Derived getType (
       final InputStream is )
       throws IOException, IllegalReadException {

               final int[] val = new int[1];
               is.getNextField(val);
               return getType(val[0]);
 }

 public  static Derived  getType (String aValue)
 {
       if ( aValue.equals(Foo.toString()) ) return BAR;
       if ( aValue.equals(Bar.toString()) ) return FOO;
       return BAR;
 }

}

-----
Thanks,

puzzlecracker



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board