Can I Change the Generated Code?

Problem

After generating a class library from your schema, you may want to add new methods and properties to the new classes. There is nothing to prevent you from doing this but if you change the schema and re-generate the code your changes will be lost.

Resolution

Within each generated source file are a number of hand coded blocks. These blocks are preserved during code generation, and allow you to change the generated code while still giving the flexibility to re-generate should your schema change.

Example

The Following shows some of the typical hand coded blocks added to each file.

  namespace ElmAdvDerivedType { public class Elm1 : LiquidTechnologies.Runtime.Net40.XmlGeneratedClass { ... protected override void Init() { ElmAdvDerivedType.Registration.iRegistrationIndicator = 0; // causes registration to take place m_Elm1Attribute = ""; _elementText = ""; _elementName = "Elm1"; // ##HAND_CODED_BLOCK_START ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS // Add Additional initilization code here... // ##HAND_CODED_BLOCK_END ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS } ... // ##HAND_CODED_BLOCK_START ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS // Add Additional Methods and members here... // ##HAND_CODED_BLOCK_END ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS } }

If we wanted to add a new property to the class we could do this here.

  namespace ElmAdvDerivedType { public class Elm1 : LiquidTechnologies.Runtime.Net40.XmlGeneratedClass { ... protected override void Init() { ElmAdvDerivedType.Registration.iRegistrationIndicator = 0; // causes registration to take place m_Elm1Attribute = ""; _elementText = ""; _elementName = "Elm1"; // ##HAND_CODED_BLOCK_START ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS _MyNewPropery = "MyValue"; // ##HAND_CODED_BLOCK_END ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS } ... // ##HAND_CODED_BLOCK_START ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS private string _MyNewPropery; public string MyNewPropery { get { return _MyNewPropery; } set { _MyNewPropery = value; } } // ##HAND_CODED_BLOCK_END ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS } }

Notes

Description Value
Article Created 2/6/2006
Versions All