I am creating a C# TBB(C# Code fragment). For that I need to write a userdefined method. I tried creating it using <%! %>. How to access the user defined method in the code. Thanks in advance. Please suggest me a way to solve this issue.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Here is the documentation reference link with example that Nickol pointing.
The TOM.NET API reference provides the following example:
In addition to the above, the following syntax is supported:
Imports the namespace enclosed between the quotation marks into the code fragment. Any class you import must be present in the Global Assembly Cache.
Declares methods, constants and classes for the rest of the code fragment to use. The declarations cannot contain the string '%>'. Note that any classes you create can only be referenced within the code fragment.
Runs a specific .NET Assembly Template Building Block, identified by the URI in the Template attribute. This statement is typically generated by SDL Tridion 2009 itself when you upload a .NET assembly, to provide access to a specific class in the .NET Assembly.
Inserts a reference to a nonstandard .NET assembly, which must be present in the Global Assembly Cache. Use the full assembly name.
Check these below links for complete details on creating Functions as well as Classes in a C# Code Fragment.
Functions: https://rcnitesh.wordpress.com/2015/04/23/functions-in-c-tbb/
[For full details including code samples, check the above link ]
Classes: https://rcnitesh.wordpress.com/2015/04/24/creating-user-defined-classes-in-c-code-fragment/ Below is an excerpt from the above Blog:
Classes are defined inside a C# Code Fragment using the construct:
<%! %>
.This USER defined class is placed as NESTED CLASS of the PREDEFINED CLASS created by Tridion when compiling the C# Code fragment. Check this blog post for in depth details on C# Code Fragment compilation and the Predefined classes , methods generated by tridion together with understanding the relation of Tridion’s Predefined class with User defined Class in a C# Code Fragment
That said above, what we need to understand is that the User defined classes in a C# Code Fragment cannot access the predefined variables like: log, engine, and package , since these variables are actually declared Private in the Predefined class generated during compilation.
[For full details including code samples, check the above links ]