DataObjectMethodAttribute クラス
アセンブリ: System (system.dll 内)

<AttributeUsageAttribute(AttributeTargets.Method)> _ Public NotInheritable Class DataObjectMethodAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Method)] public sealed class DataObjectMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)] public ref class DataObjectMethodAttribute sealed : public Attribute

DataObjectMethodAttribute を使用して、DataObjectAttribute 属性でマークされている型のデータ操作メソッドを識別し、これらがリフレクションを使用して呼び出し元によって簡単に識別されるようにできます。DataObjectMethodAttribute 属性は、メソッドに適用された場合、そのメソッドによって実行される操作の種類を示し、そのメソッドが型の既定のデータ操作メソッドであるかどうかを示します。ObjectDataSource コントロールや ObjectDataSourceDesigner クラスなどのコンポーネントは、実行時に呼び出すデータ メソッドを確認するために、この属性の値 (存在する場合) を調べます。

パブリックに公開されているメソッドに DataObjectMethodAttribute 属性を適用し、そのメソッドによって実行されるデータ操作の種類、およびそのメソッドがその型の既定のデータ メソッドかどうかを識別する方法を次のコード例に示します。この例では、NorthwindData 型によって 2 つのデータ メソッドが公開されています。1 つは GetAllEmployees という名前のデータのセットを取得するメソッドで、もう 1 つは DeleteEmployeeByID という名前のデータを削除するメソッドです。どちらのメソッドにも DataObjectMethodAttribute 属性が適用され、GetAllEmployees メソッドは Select データ操作の既定のメソッドとしてマークされ、DeleteEmployeeByID メソッドは Delete データ操作の既定のメソッドとしてマークされています。
<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 'DeleteEmployeeByID End Class 'NorthwindData
[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()); } }

System.Attribute
System.ComponentModel.DataObjectMethodAttribute


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataObjectMethodAttribute クラスのページへのリンク