Skip to content

Debugging

Simon Mourier edited this page Feb 19, 2020 · 1 revision

CodeModeler considers that during a project's lifetime, developers will have to debug the generated application. Therefore, the out-of-the-box producers add two technical items to each generated class:

  • All generated classes are marked with the DebuggerDisplayAttribute,

  • All generated classes contain a Trace method.

The DebuggerDisplayAttribute

All Business Object Model (BOM) generated classes are marked with this attribute, however its content differs from a class to another:

Entity classes are marked with a string holding the EntityKey, then the CollectionKey of the current class:

// Attribute placed on the entity class
[System.Diagnostics.DebuggerDisplayAttribute("EK={EntityKey}, Name={Name}")]

Collection classes are marked with a string holding the item count of the current collection:

// Attribute placed on the collection class
[System.Diagnostics.DebuggerDisplayAttribute("Count={Count}")]

This way when debugging the BOM in Visual Studio, placing your cursor on a CodeModeler-generated class instance will display this information in a contextual menu.

The Trace Method

Another default feature which makes it easier for developers to debug their application with CodeModeler-generated classes, is the fact that every one of those generated classes have a Trace method generated. This method is public, doesn't take any parameters, and will return a string giving a full representation of the current instance. For instance, for this model:

The Trace Method - Picture 314

The Customer entity class will hold tracing methods such as:

public string Trace()
{
    System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
    System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder, System.Globalization.CultureInfo.CurrentCulture);
    System.CodeDom.Compiler.IndentedTextWriter writer = new System.CodeDom.Compiler.IndentedTextWriter(stringWriter);
    this.BaseTrace(writer);
    writer.Flush();
    ((System.IDisposable)(writer)).Dispose();
    ((System.IDisposable)(stringWriter)).Dispose();
    string sr = stringBuilder.ToString();
    return sr;
}
 
protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
{
    writer.Write("[");
    writer.Write("Id=");
    writer.Write(this.Id);
    writer.Write(",");
    writer.Write("Name=");
    writer.Write(this.Name);
    writer.Write(",");
    writer.Write("Address=");
    writer.Write(this.Address);
    writer.Write(",");
    writer.Write("Products=");
    if ((this._products != null))
    {
        ((CodeModeler.Runtime.ICodeModelerObject)(this._products)).Trace(writer);
    }
    else
    {
        writer.Write("<null>");
    }
    writer.Write(", EntityState=");
    writer.Write(this.EntityState);
    writer.Write("]");
}

In collection classes, the BaseTrace method only prints the count of contained items.

Clone this wiki locally