DataObjectMethodAttribute 類別

定義

識別型別所公開的資料作業方法、方法所執行的作業型別,以及方法是否為預設資料方法。Identifies a data operation method exposed by a type, what type of operation the method performs, and whether the method is the default data method. 這個類別無法被繼承。This class cannot be inherited.

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

範例

下列程式碼範例示範如何將DataObjectMethodAttribute屬性套用至公開公開的方法, 並識別它所執行的資料作業類型, 以及它是否為類型的預設資料方法。The following code example demonstrates how you can apply the DataObjectMethodAttribute attribute to a publicly exposed method and identify the type of data operation it performs as well as whether it is the type's default data method. 在此範例中NorthwindData , 型別會公開兩個數據方法: 一個用來抓取GetAllEmployees一組名為的資料, DeleteEmployeeByID另一個則用來刪除名為的資料。In this example the NorthwindData type exposes two data methods: one to retrieve a set of data named GetAllEmployees, and another to delete data named DeleteEmployeeByID. 屬性會套用至這兩種方法GetAllEmployees , 方法會標示為選取DeleteEmployeeByID資料作業的預設方法, 而方法會標示為刪除資料作業的預設方法。 DataObjectMethodAttributeThe DataObjectMethodAttribute attribute is applied to both methods, the GetAllEmployees method is marked as the default method for the Select data operation, and the DeleteEmployeeByID method is marked as the default method for the Delete data operation.

[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屬性標記之類型上的資料作業方法, 讓呼叫端更輕鬆地使用反映來識別它們。You can use the DataObjectMethodAttribute to identify data operation methods on a type marked with the DataObjectAttribute attribute so that they are more easily identified by callers using reflection. DataObjectMethodAttribute當屬性套用至方法時, 它會描述方法執行的作業類型, 並指出該方法是否為類型的預設資料作業方法。When the DataObjectMethodAttribute attribute is applied to a method, it describes the type of operation the method performs and indicates whether the method is the default data operation method of a type. ObjectDataSource 控制項ObjectDataSourceDesigner和類別等元件會檢查這個屬性的值 (如果有的話), 以協助判斷在執行時間要呼叫的資料方法。Components such as the ObjectDataSource control and the ObjectDataSourceDesigner class examine the values of this attribute, if present, to help determine which data method to call at run time.

建構函式

DataObjectMethodAttribute(DataObjectMethodType)

初始化 DataObjectMethodAttribute 類別的新執行個體,並識別方法所執行的資料作業類型。Initializes a new instance of the DataObjectMethodAttribute class and identifies the type of data operation the method performs.

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

初始化 DataObjectMethodAttribute 類別的新執行個體、識別方法所執行的資料作業類型,並識別方法是否為資料物件所公開的預設資料方法。Initializes a new instance of the DataObjectMethodAttribute class, identifies the type of data operation the method performs, and identifies whether the method is the default data method that the data object exposes.

屬性

IsDefault

取得值,指出套用 DataObjectMethodAttribute 的方法是否為資料物件針對指定的方法型別所公開的預設資料方法。Gets a value indicating whether the method that the DataObjectMethodAttribute is applied to is the default data method exposed by the data object for a specific method type.

MethodType

取得 DataObjectMethodType 值,表示方法所執行的資料作業類型。Gets a DataObjectMethodType value indicating the type of data operation the method performs.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,指出這個執行個體 (Instance) 是否和指定的物件相等。Returns a value indicating whether this instance is equal to a specified object.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)
Match(Object)

取得值,指出這個執行個體是否與指定的屬性共用通用模式。Gets a value indicating whether this instance shares a common pattern with a specified attribute.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於