C# Functions
Test Your Knowledge
Task 1: Create an Inline C# Function
- Create an inline C# function “Demo.ListPages”.
- Select the Method using data connection template for the initial code.
- Change the code so that the returned XML should also include Page.Id values in the id attributes of <Page /> elements
- Preview the return value.
Task 2: Use an Input Parameter in an Inline C# Function
- Edit the Demo.ListPages function.
- Manually add a Boolean parameter “IncludeIds” to the function (on both the Source and Input Parameters tabs) setting its default value to “false”.
- Use the parameter value in the source code to choose whether to include the id attribute in the <Page/> elements.
- Preview the return value.
- Change the default value to “true” and preview the return value.
Task 3: Create an External C# Function
- In Visual Studio, create a C# method “Demo.CurrentDate”.
- Change its source code so that it should return the current date and time as a string.
- Add the method as an external C# function to C1 CMS.
Task 4: Use a C# Function on a Page
- Edit a page.
- Insert the Demo.CurrentDate function on the page.
- Preview the page and check for the correct date and time.
Task 5: Use a C# Function in an XSLT Function
- Create an XSLT function “Demo.ListPageTitles”.
- Make a function call to the Demo.ListPages function.
- Preview the input of the XSLT function.
- Change the template of the function so that it uses the retuned XML of the Demo.ListPages function to list all page titles.
- Preview the output of the XSLT function.