|
Using_writecode
Using writecode expression
Instead of creating source code in memory using CodeDOM classes it is possible to use the "writecode" expression. Writecode expression takes as argument an expression or a block of code, depending on the form used, and generates in memory the code passed as an argument using CodeDOM classes, summing up the expression writecode performs automatically work that we should do by "hand" using CodeDOM classes. Additionally writecode expression performs changes on the block passed as argument replacing identifiers marked with "$" for the content of the named variable.
To tell writecode expression we want to replace an identifier for the content of a variable we must mark the identifier with the dollar sign at the beginning, for example '$myVariable'. Below is an example: members = writecode
{%
private:
$fieldType $internalFieldName;
public:
$fieldType property $fieldName
{
get
{
return $internalFieldName;
}
set
{
$internalFieldName = value;
}
}
%};In the above example "FieldType", "internalFieldName" and "fieldName" are variables in the scope of the writecode expression. The types that can replace inside a writecode expression are: type or XplType^, block or XplFunctionBody^, XplExpression^ or exp types, XplIName^ or iname types and constants. | |||||||||||||