🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Parsed/Default String Representation and asString
This page was created by PageReplicator on 2025-09-01. Last edited by PageReplicator on 2025-09-01.

Template:Notice



You can use asString on all objects in OCL (the same way as you can in C#, for example).

When you use asString, the DefaultStringRepresentation is used to get the result string.

Note on Performance[<a href="/index.php?title=Documentation:Default_String_Representation_and_asString&veaction=edit&section=1" class="mw-editsection-visualeditor" title="Edit section: Note on Performance" data-bs-title="Documentation:Default_String_Representation_and_asString">edit</a> | <a href="/index.php?title=Documentation:Default_String_Representation_and_asString&action=edit&section=1" title="Edit section: Note on Performance" data-bs-title="Documentation:Default_String_Representation_and_asString">edit source</a>]

asString and the DefaultStringRepresentation are not <a href="/Training:Derived_attributes_%26_associations" title="Training:Derived attributes & associations" data-bs-title="Training:Derived_attributes_&_associations">subscribed</a>. This means that every time the asString is used, it needs to be reevaluated. For better performance, create a <a href="/Training:Derived_attributes_%26_associations" title="Training:Derived attributes & associations" data-bs-title="Training:Derived_attributes_&_associations">derived attribute</a> - for example, "Presentation" with the OCL - use self.Presentation in DefaultStringRepresentation.

Also, avoid using asString in other expressions that need to have high performance because they cannot subscribe properly if you use asString in the expression tree.

Keyword: Defaultstringrepresentation, asString