Functions in CodeSnippets

SyntaxEditor for Windows Forms Forum

Posted 16 years ago by Martin de Jong - Statistics Netherlands
Version: 4.0.0277
Avatar
I have a working codesnippet. Now i want to fill a Literal with the result of a function. So i added in a declaration the line:
<Function>System.DateTime.Now.ToShortDateString()</Function>

Still it uses the specified default value. Should i call some method?

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>datamodel</Title>
            <Shortcut>datamodel</Shortcut>
            <Description>Builds a 'datamodel' statement</Description>
            <Author>Blaise Team</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
        <Literal>
          <ID>name</ID>
          <ToolTip>Name of datamodel</ToolTip>
          <Default>MyDatamodel</Default>
        </Literal>
        <Literal>
          <ID>created</ID>
          <ToolTip>Date of creation</ToolTip>
          <Function>System.DateTime.Now.ToShortDateString()</Function>
          <Default>01-01-2008</Default>
        </Literal>
      </Declarations>
            <Code Language="blaise">
<![CDATA[{
Datamodel:    $name$
Date Created: $created$
}

datamodel $name$

Type
    TSexe = (Female, Male)

Block MyBlock
  Fields
    Sexe : TSexe
Endblock

Fields
    MyField : integer
    ABlock: MyBlock

Rules
  MyField
  ABlock

endmodel
]]>
            
</Snippet>
</CodeSnippet>
</CodeSnippets>
</code>

Comments (2)

Posted 16 years ago by Martin de Jong - Statistics Netherlands
Avatar
I guess implementing this yourself is the way to go? No standard function available i think:(

        protected override void OnCodeSnippetActivating(CodeSnippetEventArgs e) {
            foreach (CodeSnippetDeclaration decl in e.CodeSnippet.Declarations) {
                if (!String.IsNullOrEmpty(decl.Function)) {
                    switch (decl.Function.ToLower()) {
                        case "date":
                            decl.Default = DateTime.Now.ToShortDateString();
                            break;
                        default:
                            break;


                    }
                }
            }
            base.OnCodeSnippetActivating(e);
        }
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes that is correct.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.