Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 18th, 2013  |  syntax: None  |  size: 2.09 KB  |  views: 25  |  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 ClassExample
  2. {
  3.     public ObservableCollection<OriginalObjectType> OriginalObjectTypes { get; set; }
  4.  
  5.     public void ConvertNewObjectTypesToOriginal(ObservableCollection<ObjectType2> objectType2s)
  6.     {
  7.         ObservableCollection<OriginalObjectType> originalObjectTypesTemp = new ObservableCollection<OriginalObjectType>();
  8.  
  9.         foreach (var objectType2 in objectType2s)
  10.         {
  11.             var originalObjectType = new OriginalObjectType { Value = objectType2.Value };
  12.             originalObjectTypesTemp.Add(originalObjectType);
  13.         }
  14.  
  15.         this.OriginalObjectTypes = originalObjectTypesTemp;
  16.     }
  17.  
  18. }
  19.        
  20. public class ClassExample
  21. {    
  22.     public ObservableCollection<OriginalObjectType> OriginalObjectTypes { get; set; }      
  23.  
  24.     public void ConvertNewObjectTypesToOriginal(ObservableCollection<ObjectType2> objectType2s)
  25.      {
  26.          if (this.OriginalObjectTypes == null)
  27.              this.OriginalObjectTypes = new ObservableCollection<OriginalObjectType>();
  28.          else
  29.              this.OriginalObjectTypes.Clear();
  30.  
  31.          foreach (var objectType2 in objectType2s)        
  32.          {
  33.              var originalObjectType = new OriginalObjectType { Value = objectType2.Value };
  34.              this.OriginalObjectTypesTemp.Add(originalObjectType);
  35.          }
  36.      }  
  37. }
  38.        
  39. class ClassOne {
  40.   public ClassTwo ConvertToClassTwo() {
  41.     // do conversion
  42.   }
  43. }
  44.  
  45.  
  46. // usage:
  47. for (int64 index = 0; index < yourArray.Length; index++) {
  48.   yourArray[index] = yourArray[index].ConvertToClassTwo();
  49. }
  50.        
  51. public class ClassExample
  52. {
  53.     public ObservableCollection<OriginalObjectType> OriginalObjectTypes { get; set; }
  54.  
  55.     public void ConvertNewObjectTypesToOriginal(ObservableCollection<ObjectType2> objectType2s)
  56.     {
  57.         this.OriginalObjectTypes = new ObservableCollection<OriginalObjectType>(new List<ObjectType2>(objectType2s).ConvertAll<OriginalObjectType>(new Converter<ObjectType2, OriginalObjectType>(ConvertOT2ToOOT)));
  58.     }
  59.  
  60.     public static OriginalObjectType ConvertOT2ToOOT(ObjectType2 objectType2)
  61.     {
  62.         return new OriginalObjectType { Value = objectType2.Value };
  63.     }
  64. }
clone this paste RAW Paste Data