DataObjectMethodAttribute 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
标识由某一类型公开的数据操作方法,该方法所执行的操作类型以及该方法是否是默认的数据方法。 此类不能被继承。
public ref class DataObjectMethodAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class DataObjectMethodAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.Method)>]
type DataObjectMethodAttribute = class
    inherit AttributePublic NotInheritable Class DataObjectMethodAttribute
Inherits Attribute- 继承
- 属性
示例
下面的代码示例演示如何将 DataObjectMethodAttribute 特性应用于公开的方法,并标识它执行的数据操作的类型,以及它是否是该类型的默认数据方法。 在此示例中, NorthwindData 类型公开了两种数据方法:一种用于检索名为 GetAllEmployees的一组数据,另一种用于删除名为 的数据 DeleteEmployeeByID。 属性 DataObjectMethodAttribute 应用于这两种方法, GetAllEmployees 方法标记为选择数据操作的默认方法,方法 DeleteEmployeeByID 标记为删除数据操作的默认方法。
[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
注解
可以使用 DataObjectMethodAttribute 来标识用 DataObjectAttribute 属性标记的类型上的数据操作方法,以便调用方使用反射更轻松地识别它们。 当特性 DataObjectMethodAttribute 应用于方法时,它将描述该方法执行的操作类型,并指示该方法是否为类型的默认数据操作方法。 控件和 ObjectDataSourceDesigner 类等ObjectDataSource组件检查此属性的值(如果存在),以帮助确定在运行时要调用的数据方法。
构造函数
| DataObjectMethodAttribute(DataObjectMethodType) | 初始化 DataObjectMethodAttribute 类的新实例,并标识该方法所执行的数据操作类型。 | 
| DataObjectMethodAttribute(DataObjectMethodType, Boolean) | 初始化 DataObjectMethodAttribute 类的新实例,标识该方法所执行的数据操作类型,并标识该方法是否是该数据对象公开的默认数据方法。 | 
属性
| IsDefault | 获取一个值,该值指示 DataObjectMethodAttribute 所应用于的方法是否是由特定方法类型的数据对象所公开的默认数据方法。 | 
| MethodType | 获取一个 DataObjectMethodType 值,该值指示该方法所执行的数据操作类型。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 返回一个值,该值指示此实例是否等于指定的对象。 | 
| GetHashCode() | 返回此实例的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 获取一个值,该值指示此实例是否与指定特性共享一个通用模式。 | 
| 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) |