Let's say I have the following classes.
public class MyClass {
public string Data1 { get; set; }
public MyOtherClass Data2 { get; set; }
// 50+ other properties...
}
public class MyOtherClass {
public string OtherData1 { get; set; }
// More properties
}
There's somecode that instanciate that class and populates it with all the data. I'd like to use that object for my test. I could simply serialize the structure into XML and reload it later. However, what I would really like is to have the entire object tree build in the code. In other words:
MyClass myClass = new MyClass {
Data1 = "Hello",
Data2 = new MyOtherClass {
OtherData1 = "World",
// More...
},
// More...
}
I could write all that myself, but it would take hours and be error prone since there's a high number of properties and sub-classes. Here's my question: given an object how would you generate the code which populate that object?
I would write a T4 template. Check out an example that is doing something, although really remotely, similar to what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With