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
public sealed class DataObjectAttribute : 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

注解

使用 DataObjectAttribute 特性来标识对象,使其适合 ObjectDataSource 对象使用。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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。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)

适用于