C# Functions

Test Your Knowledge

Task 1: Create an Inline C# Function

  1. Create an inline C# function “Demo.ListPages”.
  2. Select the Method using data connection template for the initial code.
  3. Change the code so that the returned XML should also include Page.Id values in the id attributes of <Page /> elements
  4. Preview the return value.

Task 2: Use an Input Parameter in an Inline C# Function

  1. Edit the Demo.ListPages function.
  2. Manually add a Boolean parameter “IncludeIds” to the function (on both the Source and Input Parameters tabs) setting its default value to “false”.
  3. Use the parameter value in the source code to choose whether to include the id attribute in the <Page/> elements.
  4. Preview the return value.
  5. Change the default value to “true” and preview the return value.

Task 3: Create an External C# Function

  1. In Visual Studio, create a C# method “Demo.CurrentDate”.
  2. Change its source code so that it should return the current date and time as a string.
  3. Add the method as an external C# function to C1 CMS.

Task 4: Use a C# Function on a Page

  1. Edit a page.
  2. Insert the Demo.CurrentDate function on the page.
  3. Preview the page and check for the correct date and time.

Task 5: Use a C# Function in an XSLT Function

  1. Create an XSLT function “Demo.ListPageTitles”.
  2. Make a function call to the Demo.ListPages function.
  3. Preview the input of the XSLT function.
  4. Change the template of the function so that it uses the retuned XML of the Demo.ListPages function to list all page titles.
  5. Preview the output of the XSLT function.