wu :: forums
« wu :: forums - using enum or old-fashion way in C# »

Welcome, Guest. Please Login or Register.
Apr 19th, 2024, 7:17am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Icarus, Grimbal, SMQ, william wu, towr, Eigenray, ThudnBlunder)
   using enum or old-fashion way in C#
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: using enum or old-fashion way in C#  (Read 1385 times)
puzzlecracker
Senior Riddler
****



Men have become the tools of their tools

   


Gender: male
Posts: 319
using enum or old-fashion way in C#  
« on: Sep 28th, 2008, 3:51pm »
Quote Quote Modify Modify

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
« Last Edit: Sep 28th, 2008, 3:52pm by puzzlecracker » IP Logged

While we are postponing, life speeds by
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

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