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元件會檢查此屬性的值,如果有的話,可協助判斷運行時間所要呼叫的數據方法。

建構函式

DataObjectMethodAttribute(DataObjectMethodType)

初始化 DataObjectMethodAttribute 類別的新執行個體,並識別方法所執行的資料作業類型。

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

初始化 DataObjectMethodAttribute 類別的新執行個體、識別方法所執行的資料作業類型,並識別方法是否為資料物件所公開的預設資料方法。

屬性

IsDefault

取得值,指出套用 DataObjectMethodAttribute 的方法是否為資料物件針對指定的方法型別所公開的預設資料方法。

MethodType

取得 DataObjectMethodType 值,表示方法所執行的資料作業類型。

TypeId

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

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,該值表示這個執行個體是否和指定的物件相等。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

取得值,指出這個執行個體是否與指定的屬性共用通用模式。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

_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)

適用於