Want more features on Pastebin? Sign Up, it's FREE!
Guest

Traversing an arbitrary C# object graph using XPath/applying XSL transforms

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 0.93 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class SomeType {
  2.    public int myInt  { get; set; }
  3. }
  4.  
  5. public class AnotherType {
  6.    public string myString { get; set; }
  7.    public SomeType mySomeType { get; set; }
  8. }
  9.  
  10. public class LastType {
  11.    public SomeType mySomeType { get; set; }
  12.    public AnotherType myAnotherType { get; set; }
  13. }
  14.  
  15. public class UserTypes{
  16.     static void Main()
  17.     {
  18.         LastType lt = new LastType();
  19.         SomeType st = new SomeType();
  20.         AnotherType atype = new AnotherType();
  21.  
  22.         st.myInt = 7;
  23.         atype.myString = "BOB";
  24.         atype.mySomeType = st;
  25.         lt.mySomeType = st;
  26.         lt.myAnotherType = atype;
  27.  
  28.         string xmlOutput = YourAwesomeFunction(lt);
  29.     }
  30. }
  31.        
  32. <ObjectMap>
  33.  <LastType id="0">
  34.    <mySomeType idref="1" />
  35.    <myAnotherType idref="2" />
  36.  </LastType>
  37.  
  38.  <SomeType id="1">
  39.   <myInt>7</myInt>
  40.  </SomeType>
  41.  
  42.  <AnotherType id="2">
  43.   <myString>BOB</myString>
  44.   <mySomeType idref="1" />
  45.  </AnotherType>
  46. </ObjectMap>
clone this paste RAW Paste Data