DataObjectMethodAttribute コンストラクター

定義

DataObjectMethodAttribute クラスの新しいインスタンスを初期化します。

オーバーロード

DataObjectMethodAttribute(DataObjectMethodType)

DataObjectMethodAttribute クラスの新しいインスタンスを初期化し、メソッドによって実行されるデータ操作の種類を識別します。

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

DataObjectMethodAttribute クラスの新しいインスタンスを初期化して、メソッドによって実行されるデータ操作の種類を識別し、さらにそのメソッドがそのデータ オブジェクトによって公開される既定のデータ メソッドかどうかを識別します。

DataObjectMethodAttribute(DataObjectMethodType)

ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs

DataObjectMethodAttribute クラスの新しいインスタンスを初期化し、メソッドによって実行されるデータ操作の種類を識別します。

public:
 DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType methodType);
public DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType methodType);
new System.ComponentModel.DataObjectMethodAttribute : System.ComponentModel.DataObjectMethodType -> System.ComponentModel.DataObjectMethodAttribute
Public Sub New (methodType As DataObjectMethodType)

パラメーター

methodType
DataObjectMethodType

メソッドによって実行されるデータ操作を示す DataObjectMethodType 値の 1 つ。

次のコード例では、 属性を DataObjectMethodAttribute パブリックに公開されたメソッドに適用し、実行するデータ操作の種類と、それが型の既定のデータ メソッドであるかどうかを識別する方法を示します。 この例では、型は NorthwindData 2 つのデータ メソッドを公開します。1 つは という名前 GetAllEmployeesのデータ セットを取得し、もう 1 つは という名前 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

注釈

プロパティはIsDefault、このDataObjectMethodAttribute(DataObjectMethodType)コンストラクターを使用してオブジェクトをDataObjectMethodAttribute作成するときに にfalse設定されます。

適用対象

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs

DataObjectMethodAttribute クラスの新しいインスタンスを初期化して、メソッドによって実行されるデータ操作の種類を識別し、さらにそのメソッドがそのデータ オブジェクトによって公開される既定のデータ メソッドかどうかを識別します。

public:
 DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType methodType, bool isDefault);
public DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType methodType, bool isDefault);
new System.ComponentModel.DataObjectMethodAttribute : System.ComponentModel.DataObjectMethodType * bool -> System.ComponentModel.DataObjectMethodAttribute
Public Sub New (methodType As DataObjectMethodType, isDefault As Boolean)

パラメーター

methodType
DataObjectMethodType

メソッドによって実行されるデータ操作を示す DataObjectMethodType 値の 1 つ。

isDefault
Boolean

この属性が適用されるメソッドが、指定した methodType のデータ オブジェクトの既定のメソッドである場合は true。それ以外の場合は false

次のコード例では、 属性を DataObjectMethodAttribute パブリックに公開されたメソッドに適用し、実行するデータ操作の種類と、それが型の既定のデータ メソッドであるかどうかを識別する方法を示します。 この例では、型は NorthwindData 2 つのデータ メソッドを公開します。1 つは という名前 GetAllEmployeesのデータ セットを取得し、もう 1 つは という名前 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

適用対象