DataObjectMethodAttribute 類別

定義

識別由類型公開的數據作業方法、方法所執行的作業類型,以及方法是否為預設數據方法。 此類別無法獲得繼承。

public ref class DataObjectMethodAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class DataObjectMethodAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type DataObjectMethodAttribute = class
    inherit Attribute
Public NotInheritable Class DataObjectMethodAttribute
Inherits Attribute
繼承
DataObjectMethodAttribute
屬性

範例

以下程式碼範例示範如何將該屬性套用 DataObjectMethodAttribute 到公開暴露的方法,並識別它執行的資料操作類型,以及是否為該類型的預設資料方法。 在此範例中,該 NorthwindData 型別暴露了兩種資料方法:一種是檢索一組名為 GetAllEmployees的資料,另一種是刪除名為 DeleteEmployeeByID的資料。 屬性 DataObjectMethodAttribute 套用於兩個方法,該 GetAllEmployees 方法標記為 Select 資料操作的預設方法, DeleteEmployeeByID 該方法則標記為 Delete 資料操作的預設方法。

[DataObjectAttribute]
public class NorthwindData
{  
  public NorthwindData() {}

  [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  public static IEnumerable GetAllEmployees()
  {
    AccessDataSource ads = new AccessDataSource();
    ads.DataSourceMode = SqlDataSourceMode.DataReader;
    ads.DataFile = "~//App_Data//Northwind.mdb";
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees";
    return ads.Select(DataSourceSelectArguments.Empty);
  }

  // Delete the Employee by ID.
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  public void DeleteEmployeeByID(int employeeID)
  {
    throw new Exception("The value passed to the delete method is "
                         + employeeID.ToString());
  }
}
<DataObjectAttribute()> _
Public Class NorthwindData

  <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
  Public Shared Function GetAllEmployees() As IEnumerable
    Dim ads As New AccessDataSource()
    ads.DataSourceMode = SqlDataSourceMode.DataReader
    ads.DataFile = "~/App_Data/Northwind.mdb"
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees"
    Return ads.Select(DataSourceSelectArguments.Empty)
  End Function 'GetAllEmployees

  ' Delete the Employee by ID.
  <DataObjectMethodAttribute(DataObjectMethodType.Delete, True)> _
  Public Sub DeleteEmployeeByID(ByVal employeeID As Integer)
    Throw New Exception("The value passed to the delete method is " + employeeID.ToString())
  End Sub

End Class

備註

你可以用 來 DataObjectMethodAttribute 識別標記為屬性 DataObjectAttribute 的型別資料操作方法,讓呼叫者更容易透過反射來辨識。 當該 DataObjectMethodAttribute 屬性套用到某個方法時,它描述了該方法執行的操作類型,並指示該方法是否是某類型的預設資料操作方法。 像控制項和ObjectDataSourceDesigner類別這類元件ObjectDataSource會檢查這個屬性的值(如果存在),以協助判斷執行時要呼叫哪個資料方法。

建構函式

名稱 Description
DataObjectMethodAttribute(DataObjectMethodType, Boolean)

初始化該類別的新實例 DataObjectMethodAttribute ,識別該方法執行的資料操作類型,並判斷該方法是否為資料物件所暴露的預設資料方法。

DataObjectMethodAttribute(DataObjectMethodType)

初始化該類別的新實例 DataObjectMethodAttribute ,並識別該方法執行的資料操作類型。

屬性

名稱 Description
IsDefault

會取得一個值,表示該方法 DataObjectMethodAttribute 套用的是否是資料物件針對特定方法類型所暴露的預設資料方法。

MethodType

會獲得 DataObjectMethodType 一個值,表示該方法執行的資料操作類型。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

傳回值,指出這個實例是否等於指定的物件。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

會取得一個值,表示此實例是否與特定屬性共享共同模式。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於