Created
March 31, 2016 14:36
-
-
Save OlegJakushkin/c2827aea821eac552bcd58621ad3fc23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace A | |
{ | |
public class Inner | |
{ | |
public class InnerInner | |
{ | |
public int Momom; | |
} | |
} | |
public class Do | |
{ | |
public int Bebe | |
{ | |
get; set; | |
} | |
public Inner.InnerInner InnerInner; | |
public int Ababa; | |
} | |
} | |
namespace B | |
{ | |
public class Inner | |
{ | |
public class InnerInner | |
{ | |
public int Momom; | |
} | |
} | |
public class Do | |
{ | |
public int Bebe | |
{ | |
get; set; | |
} | |
public Inner.InnerInner InnerInner; | |
public int Ababa; | |
} | |
} | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static T Convert<T>(object From) where T: class | |
{ | |
Type valueType = From.GetType(); | |
System.Xml.Serialization.XmlSerializer xmlSerializer = | |
new System.Xml.Serialization.XmlSerializer(valueType); | |
StringBuilder stringBuilder = new StringBuilder(); | |
System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder); | |
xmlSerializer.Serialize(stringWriter, From); | |
string soapSerializedValueObject = stringBuilder.ToString(); | |
System.Xml.XmlTextReader xmlTextReader = | |
new System.Xml.XmlTextReader(new System.IO.StringReader(soapSerializedValueObject)); | |
System.Xml.Serialization.XmlSerializer mySerializer = new | |
System.Xml.Serialization.XmlSerializer | |
(typeof(T)); | |
object newValueObject = mySerializer.Deserialize(xmlTextReader); | |
return newValueObject as T; | |
} | |
static void Main(string[] args) | |
{ | |
var before = new A.Do(); | |
before.Ababa = 55; | |
before.Bebe = 44; | |
before.InnerInner = new A.Inner.InnerInner(); | |
before.InnerInner.Momom = 356; | |
Console.WriteLine(before.Ababa + " " + before.Bebe + " " + before.InnerInner.Momom); | |
var after = Convert<B.Do>(before); | |
Console.WriteLine(after.Ababa + " " + after.Bebe + " " + after.InnerInner.Momom); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment