0

Input pre-processed xml files to map a specific transaction type

Say I have transactionTypeA transactionTypeB transactionTypeC, (all inherited from TransactionTypes). the following code, just for reference, is good for a specific transaction type. for example, mapping xml data into transactionTypeA:

byte[] byteArray = Encoding.UTF8.GetBytes(xmlContent);
MemoryStream tempMemoryStream = new MemoryStream(byteArray);
DataContractSerializer serializer = new DataContractSerializer(typeof(transactionTypeA));
transactionTypeA variavlename= (transactionTypeA)serializer.ReadObject(tempMemoryStream);

Now, I want to make it generic, so that when an xml file is in, I can tell which specific transaction it is.

DataContractSerializer serializer = new DataContractSerializer(typeof(ThatCorrespondingTransactionType));
    ThatCorrespondingTransactionType variavlename= (ThatCorrespondingTransactionType)serializer.ReadObject(tempMemoryStream)

Any help please? I have tried to just use the root parent TransactionTypes, but it gives : SerializationException was unhandled by user code.

Thanks a lot.

user2751691
  • 401
  • 2
  • 10
  • 32
  • Maybe? http://stackoverflow.com/questions/13704752/deserialize-xml-to-object-using-dynamic – I4V Sep 25 '13 at 16:04
  • Are you looking to map to a `dynamic` class or are you looking to map to a generic type parameter? – 48klocs Sep 25 '13 at 16:05
  • will each class contain different members? how are the types different? – jamesdeath123 Oct 02 '13 at 18:28
  • the problem is solved yesterday, using the xlst to convert the input xml to type of the parent xml format. There should be other good ways, as all the classes are defined with [knownType class definition]. but i dont know : ) – user2751691 Oct 03 '13 at 13:20

0 Answers0