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)

适用于