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 物件會在解析頁面時回傳資源檔案中的該值。

建構函式

名稱 Description
ResourceExpressionBuilder()

初始化 ResourceExpressionBuilder 類別的新執行個體。

屬性

名稱 Description
SupportsEvaluate

回傳一個值,表示在使用無編譯功能的頁面中,是否能評估表達式。

方法

名稱 Description
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)

適用於

另請參閱