Click here to Skip to main content
15,887,888 members
Home / Discussions / C#
   

C#

 
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 
QuestionSimple C# Text Recognition Pin
Reelix6-May-08 3:14
Reelix6-May-08 3:14 
AnswerRe: Simple C# Text Recognition Pin
J a a n s6-May-08 3:39
professionalJ a a n s6-May-08 3:39 
GeneralRe: Simple C# Text Recognition Pin
Reelix6-May-08 3:42
Reelix6-May-08 3:42 
QuestionHow to create custom Globalization for fomatting numbers ? Pin
hdv2126-May-08 3:13
hdv2126-May-08 3:13 
QuestionWorkFlow Error (Hellp Me Please) Pin
Thaer Hamael6-May-08 2:48
Thaer Hamael6-May-08 2:48 
QuestionCreate a PDF Library to add checkbox, textbox etc in PDF document Pin
Munal Kalyan6-May-08 2:48
Munal Kalyan6-May-08 2:48 
AnswerRe: Create a PDF Library to add checkbox, textbox etc in PDF document Pin
Dave Kreskowiak6-May-08 4:06
mveDave Kreskowiak6-May-08 4:06 
QuestionAdd to Resource (.resx) file problem Pin
Krishnraj6-May-08 2:47
Krishnraj6-May-08 2:47 
AnswerRe: Add to Resource (.resx) file problem Pin
Reelix6-May-08 3:09
Reelix6-May-08 3:09 
QuestionContext Menu problem Pin
Ballita6-May-08 2:22
Ballita6-May-08 2:22 

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.