DataObjectAttribute 類別

定義

將型別識別為適合繫結至 ObjectDataSource 物件的物件。Identifies a type as an object suitable for binding to an ObjectDataSource object. 這個類別無法被繼承。This class cannot be inherited.

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

範例

下列程式碼範例將示範如何DataObjectAttribute套用屬性, 以指出物件適用于系結ObjectDataSource至物件。The following code example demonstrates how you can apply the DataObjectAttribute attribute to indicate an object is suitable for binding to an ObjectDataSource object. 在此範例中, NorthwindData物件適用于ObjectDataSource物件。In this example, the NorthwindData object is intended for use with an ObjectDataSource object.

[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

備註

您可以使用ObjectDataSource 屬性,將物件識別為DataObjectAttribute適合物件使用。Use the DataObjectAttribute attribute to identify an object as suitable for use by an ObjectDataSource object. 設計階段類別 (例如ObjectDataSourceDesigner類別) 會DataObjectAttribute使用屬性來呈現適當的ObjectDataSource物件, 以系結至物件。Design-time classes such as the ObjectDataSourceDesigner class use the DataObjectAttribute attribute to present suitable objects to bind to an ObjectDataSource object.

如需使用屬性的詳細資訊, 請參閱屬性For more information about using attributes, see Attributes.

建構函式

DataObjectAttribute()

初始化 DataObjectAttribute 類別的新執行個體。Initializes a new instance of the DataObjectAttribute class.

DataObjectAttribute(Boolean)

初始化 DataObjectAttribute 類別的新執行個體,並指出物件是否適合繫結至 ObjectDataSource 物件。Initializes a new instance of the DataObjectAttribute class and indicates whether an object is suitable for binding to an ObjectDataSource object.

欄位

DataObject

表示類別在設計階段適合繫結至 ObjectDataSource 物件。Indicates that the class is suitable for binding to an ObjectDataSource object at design time. 此欄位為唯讀。This field is read-only.

Default

表示 DataObjectAttribute 類別的預設值,表示類別在設計階段適合繫結至 ObjectDataSource 物件。Represents the default value of the DataObjectAttribute class, which indicates that the class is suitable for binding to an ObjectDataSource object at design time. 此欄位為唯讀。This field is read-only.

NonDataObject

表示類別在設計階段不適合繫結至 ObjectDataSource 物件。Indicates that the class is not suitable for binding to an ObjectDataSource object at design time. 此欄位為唯讀。This field is read-only.

屬性

IsDataObject

取得值,指出物件在設計階段是否應被視為適合繫結至 ObjectDataSource 物件。Gets a value indicating whether an object should be considered suitable for binding to an ObjectDataSource object at design time.

TypeId

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

(繼承來源 Attribute)

方法

Equals(Object)

判斷這個 DataObjectAttribute 的執行個體是否符合另一個物件的模式。Determines whether this instance of DataObjectAttribute fits the pattern of another object.

GetHashCode()

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

GetType()

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

(繼承來源 Object)
IsDefaultAttribute()

取得值,指出目前屬性值是否為屬性的預設值。Gets a value indicating whether the current value of the attribute is the default value for the attribute.

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 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)

適用於