如何添加在C#TBB(C#代码段),用户自定义的方法呢​​? [英] How to add user defined methods in C# TBB(C# code fragment)?

查看:281
本文介绍了如何添加在C#TBB(C#代码段),用户自定义的方法呢​​?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个C#TBB(C#代码片段)。为此,我需要写一个用户定义的方法。我试着用<创造它;%! %>。如何访问代码中的用户定义的方法。提前致谢。请给我建议的方式来解决这个问题。

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.

推荐答案

该TOM.NET API参考提供了以下例子:

The TOM.NET API reference provides the following example:

<%@ Import Namespace="Tridion.ContentManager.Publishing"%>
<%!
private string ExtraString()
{
    return "Something added by the C# template";
}
%>
log.Debug("Executing C# template");
if (engine.RenderMode == RenderMode.Publish)
{
    package.GetByName(Package.OutputName).AppendToStringValue(ExtraString());
}

在除上述以外,支持以下语法:

In addition to the above, the following syntax is supported:

<%@Import Namespace="..." %> 



导入包围的引号之间插入代码段的命名空间。你输入的任何类必须存在于全局程序集缓存。

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.

<%RunTemplate Template="tcm:1-184-2048" Class="Tridion.Templating.Examples.ExampleTemplateClass"%> 



运行特定的.NET程序集模板构建块,由URI在模板属性标识。本声明乃支持SDL Tridion 2009年自己当您上传.NET程序集,提供访问一个特定的类在.NET组件通常产生的。

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.

<%@Assembly Name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%> 

插入到一个非标准的.NET程序集,它必须存在于全局程序集缓存的参考。使用完整的程序集名称。

Inserts a reference to a nonstandard .NET assembly, which must be present in the Global Assembly Cache. Use the full assembly name.

这篇关于如何添加在C#TBB(C#代码段),用户自定义的方法呢​​?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆