This project is read-only.

Code Generation

ToDoListLib starts with the most current XML maintained by the ToDoList software. From the XML, a XSD schema file is generated. From that file C# classes are generated. Someone might ask why we don't just stop there and use those generated classes. But the schema generated from the XML is unaware of the data types or relationships of the data, and everything in the C# class is either a String or an array of objects that usually have nothing but a single String value. So the ToDoListLib uses those generated classes to serialize and deserialize objects, but then wraps the resulting simple Strings and Arrays with "Safe" strongly-typed classes.

Here are the steps required to get the schema and base classes.

You don't need to do this when you first get the library. You only need to do it if you upgrade ToDoList and you want to see if the library is still compliant with the latest updates fro Dan G.

  1. Locate the XSD_Prototype.tdl file provided with the library. This has tasks which make use of all known features, and as such it can be used to generate a schema.
  2. Delete the file TdlSchema.xml from your current ToDoListLib project folder, if it exists.
  3. Copy XSD_Prototype.tdl to the project folder.
  4. Rename XSD_Prototype.tdl to TdlSchema.xml.
  5. Use the xsd tool from the VS Command Prompt as follows:

               xsd TdlSchema.xml

  6. That creates a new TdlSchema.xsd file.
  7. Use the xsd tool from the VS Command Prompt as follows:

               xsd TdlSchema.xsd /c /n:ToDoListLib

  8. That generates the file TdlSchema.cs.
  9. If you already have Visual Studio open, it should notify you that project files have changed. Yes to All to reload the files.
  10. If the schema has changed, SafeTask.cs (one of the ToDoListLib classes) and perhaps other files will show new errors. Even if there are no errors, there is no guarantee that everything is OK. But address errors first and test for other regressions later.

If you are creating a new project or just adding these files for the first time:

You don't want to manually add the .cs file directly into the ToDoListLib project. The ToDoListLib project should already include the TdlSchema.xsd. If it does, then that already has a reference to the .cs under it. If the project does not have the .xsd file, use Add Item>Existing, and open the .xsd file, nothing else.

The XSD file type is treated as a parent file, much like a Windows Form is a container for "child" files, with both a designer file as well as the code-behind. WebForms also have a .aspx file and associated code-behind and designer files. The XSD file is imported into Visual studio, and the .cs file is automatically pulled in and treated as a child file. Other files are created at this time.

If something goes wrong in this process, delete the TdlSchema.xsd from the project (automatically deletes child files) and repeat the steps above with the xsd tool. Use Add Item>Existing to bring in the .xsd as above.

Build errors

When the .xsd file initially created, it includes a NewDataSet class in the TdlSchema.cs file. As might be expected, it also creates a corresponding class in the TdlSchema.Designer.cs file. This is OK because both definitions are Partial. However, the xsd tool decorates both class definitions with the same Attribute/Flags, and the compiler doesn't allow this. The solution is to look in your Visual Studio Errors view, click each notice of a Duplicate 'global::...' attribute, and then delete the line flagged.

When do we need to do this?

If you are actively maintaining this library then the pattern is to get a good XML file, convert to XSD, convert that to C#, then check the library to see what's broken. If you are not maintaining the library itself, you don't need to do this. Just download the latest library release.

Where does XSD_Prototype.tdl come from?

This was created to exercise the features in ToDoList. You can open it on your desktop with TDL. If there is a new TDL feature, add a task or two to use the new feature, save the .tdl, then follow the instructions above. If you find a feature that is not supported, please open a new issue report, make the .tdl file available somewhere, and identify the specific version of TDL that you're using.

See the Sync page for more information about how these files are to be kept in sync with TDL when Dan posts updates.


Last edited Feb 10, 2014 at 6:10 AM by TonyGravagno, version 2