ResourceExpressionBuilder 类

定义

为页面分析器提供代码,用于在控件上分配属性值。

public ref class ResourceExpressionBuilder : System::Web::Compilation::ExpressionBuilder
public class ResourceExpressionBuilder : System.Web.Compilation.ExpressionBuilder
type ResourceExpressionBuilder = class
    inherit ExpressionBuilder
Public Class ResourceExpressionBuilder
Inherits ExpressionBuilder
继承
ResourceExpressionBuilder

示例

下面的代码示例从资源文件中检索默认货币。

<%@ Page Language="C#" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Sales Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        All prices listed in 
        <asp:Literal ID="Literal1" runat="server" 
        Text="<%$ Resources: Financial, Currency %>" />.
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Sales Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        All prices listed in 
        <asp:Literal ID="Literal1" runat="server" 
        Text="<%$ Resources: Financial, Currency %>" />.
    </div>
    </form>
</body>
</html>

此代码从App_GlobalResources目录中命名 Financial.resx 的资源文件中读取以下值。

<data name="Currency"><value xml:space="preserve">US dollars</value></data>

注解

ResourceExpressionBuilder 类创建代码,用于在执行页面时检索资源值。 资源文件通常包含针对特定语言或区域性本地化的信息。

资源表达式采用页面内的窗体 <%$ Resources: ClassKey, ResourceKey %> 。 冒号之前的表达式部分(:)指定要使用的表达式生成器的类型,冒号后面的部分表示类名和资源键。 前面的表达式将从名为 ClassKey.resx 的文件中检索以下值:

<data name="ResourceKey"><value xml:space="preserve">Hello!</value></data>

当页面分析器遇到带有前缀的 Resources 表达式时,它将创建类的 ResourceExpressionBuilder 实例。 该 ResourceExpressionBuilder 类计算表达式或生成代码,以便在执行页面时返回表达式的值。

如果在将编译的页面中遇到表达式,该 ResourceExpressionBuilder 对象将生成从资源文件中检索指定值的代码。 如果在不会编译的页面中遇到表达式,则当分析页面时,该 ResourceExpressionBuilder 对象将从资源文件返回值。

构造函数

名称 说明
ResourceExpressionBuilder()

初始化 ResourceExpressionBuilder 类的新实例。

属性

名称 说明
SupportsEvaluate

返回一个值,该值指示是否可以在使用无编译功能的页面中计算表达式。

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
EvaluateExpression(Object, BoundPropertyEntry, Object, ExpressionBuilderContext)

从资源文件返回一个值。

GetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext)

返回在页面执行期间要计算的代码表达式。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ParseExpression(String, Type, ExpressionBuilderContext)

返回一个对象,该对象表示已分析的表达式。

ParseExpression(String)

返回一个对象,该对象表示已分析的表达式。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅