Click here to Skip to main content
15,898,374 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using "using" Pin
Roger Alsing6-May-08 7:10
Roger Alsing6-May-08 7:10 
AnswerRe: Using "using" Pin
Guffa6-May-08 4:37
Guffa6-May-08 4:37 
GeneralRe: Using "using" Pin
Roger Alsing6-May-08 7:45
Roger Alsing6-May-08 7:45 
GeneralRe: Using "using" Pin
Guffa6-May-08 9:53
Guffa6-May-08 9:53 
AnswerRe: Using "using" Pin
S. Senthil Kumar6-May-08 4:43
S. Senthil Kumar6-May-08 4:43 
AnswerRe: Using "using" Pin
DavidNohejl6-May-08 4:50
DavidNohejl6-May-08 4:50 
GeneralRe: Using "using" Pin
Pete O'Hanlon6-May-08 9:01
mvePete O'Hanlon6-May-08 9:01 
AnswerRe: Using "using" Pin
PIEBALDconsult6-May-08 5:25
mvePIEBALDconsult6-May-08 5:25 
GeneralRe: Using "using" Pin
Spacix One6-May-08 10:20
Spacix One6-May-08 10:20 
GeneralRe: Using "using" Pin
PIEBALDconsult6-May-08 12:24
mvePIEBALDconsult6-May-08 12:24 
QuestionConverting ActiveDirectory createTimeStamp to DateTime [modified] Pin
scotlfs6-May-08 3:59
scotlfs6-May-08 3:59 
AnswerRe: Converting ActiveDirectory createTimeStamp to DateTime Pin
scotlfs6-May-08 4:38
scotlfs6-May-08 4:38 
QuestionEnums and text descriptions Pin
MrEyes6-May-08 3:41
MrEyes6-May-08 3:41 
AnswerRe: Enums and text descriptions Pin
CPallini6-May-08 3:48
mveCPallini6-May-08 3:48 
AnswerRe: Enums and text descriptions Pin
J4amieC6-May-08 3:49
J4amieC6-May-08 3:49 
GeneralRe: Enums and text descriptions Pin
MrEyes6-May-08 4:13
MrEyes6-May-08 4:13 
GeneralRe: Enums and text descriptions Pin
J4amieC6-May-08 4:17
J4amieC6-May-08 4:17 
GeneralRe: Enums and text descriptions Pin
MrEyes6-May-08 5:01
MrEyes6-May-08 5:01 
Well to cut a very long story short I am currently in the throws of creating an XML data transformation library. Unfortunately for me neither XML structure can be schema'd and these are also out of my control and cannot be change.

To get around this I have created a series of enums for the 100's of different keys these items contain, so now I am trying to create mapping data from one to the other.

It could be done with switch/case statements, however this is messy and will be complicated to maintain. So I am attempting to use attributes on the input enums to easily convert these to the output format.

So for example each data structure contains the concept of Address Type, e.g.

public enum OutputAddressType
{
  [Description("ResidentialAddress")]
  Residential,
  [Description("CommercialAddress")]
  Commericial,
  [Description("UnknownAddress")]
  Unknown,
  
}

public enum InputAddressType
{
  [Description("ADR001")]
  Home,
  [Description("ADR002")]
  HomeSecondary,
  [Description("ADR003")]
  Business
}


Now as I iterate through the input data object address values, I currently have a switch case that looks something like this:

switch(input.AddressType)
{
  case InputAddressType.Home:
   this.output.AddressType = OutputAddressType.ResidentialAddress;
  break;
  case InputAddressType.HomeSecondary:
   this.output.AddressType = OutputAddressType.Unknown;
  break;
  case InputAddressType.Business:
   this.output.AddressType = OutputAddressType.CommercialAddress;
  break;
}


It would be great if I could do something like this to the input enum:

public enum InputAddressType
{
  [ObjectDescription(InputAddressType.ResidentialAddress)]
  [Description("ADR001")]
  Home,
  [ObjectDescription(InputAddressType.Unknown)]
  [Description("ADR002")]
  HomeSecondary,
  [ObjectDescription(InputAddressType.CommercialAddress)]
  [Description("ADR003")]
  Business
}


The example above is a simple example, however if you imagine that there are over 200 of these enums, each having anywhere from 2 to 200 values you can see why having loads of switch/cases is unmaintainable. Also in the example there is a direct 1 to 1 map from input to output, however in the real world this is a rarity.
GeneralRe: Enums and text descriptions Pin
PIEBALDconsult6-May-08 5:34
mvePIEBALDconsult6-May-08 5:34 
GeneralRe: Enums and text descriptions Pin
MrEyes6-May-08 5:50
MrEyes6-May-08 5:50 
GeneralRe: Enums and text descriptions Pin
PIEBALDconsult6-May-08 5:28
mvePIEBALDconsult6-May-08 5:28 
GeneralRe: Enums and text descriptions Pin
PIEBALDconsult6-May-08 5:30
mvePIEBALDconsult6-May-08 5:30 
GeneralRe: Enums and text descriptions Pin
J4amieC6-May-08 6:03
J4amieC6-May-08 6:03 
GeneralRe: Enums and text descriptions Pin
PIEBALDconsult6-May-08 12:31
mvePIEBALDconsult6-May-08 12:31 
AnswerRe: Enums and text descriptions Pin
PIEBALDconsult6-May-08 5:31
mvePIEBALDconsult6-May-08 5:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.