DataObjectAttribute 类

定义

将类型标识为适合绑定到 ObjectDataSource 对象的对象。 此类不能被继承。

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

示例

下面的代码示例演示如何应用 DataObjectAttribute 特性来指示对象适合绑定到对象 ObjectDataSource 。 在此示例中,该 NorthwindData 对象用于对象 ObjectDataSource

[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 的对象。 设计时类(如 ObjectDataSourceDesigner 类) DataObjectAttribute 使用特性来呈现要绑定到对象的 ObjectDataSource 合适对象。

有关使用属性的详细信息,请参阅 “属性”。

构造函数

名称 说明
DataObjectAttribute()

初始化 DataObjectAttribute 类的新实例。

DataObjectAttribute(Boolean)

初始化类的新实例 DataObjectAttribute ,并指示对象是否适合绑定到对象 ObjectDataSource

字段

名称 说明
DataObject

指示类适合在设计时绑定到 ObjectDataSource 对象。 此字段是只读的。

Default

表示类的 DataObjectAttribute 默认值,指示类适合在设计时绑定到 ObjectDataSource 对象。 此字段是只读的。

NonDataObject

指示类不适合在设计时绑定到 ObjectDataSource 对象。 此字段是只读的。

属性

名称 说明
IsDataObject

获取一个值,该值指示在设计时是否应将对象视为适合绑定到 ObjectDataSource 对象。

TypeId

在派生类中实现时,获取此 Attribute的唯一标识符。

(继承自 Attribute)

方法

名称 说明
Equals(Object)

确定此实例 DataObjectAttribute 是否适合另一个对象的模式。

GetHashCode()

返回此实例的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

获取一个值,该值指示属性的当前值是否为属性的默认值。

Match(Object)

在派生类中重写时,返回一个值,该值指示此实例是否等于指定对象。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

显式接口实现

名称 说明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,该信息可用于获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对对象公开的属性和方法的访问。

(继承自 Attribute)

适用于