Rediger

Del via


DataObjectMethodAttribute Class

Definition

Identifies a data operation method exposed by a type, what type of operation the method performs, and whether the method is the default data method. This class cannot be inherited.

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 Attribute
Public NotInheritable Class DataObjectMethodAttribute
Inherits Attribute
Inheritance
DataObjectMethodAttribute
Attributes

Examples

The following code example demonstrates how you can apply the DataObjectMethodAttribute attribute to a publicly exposed method and identify the type of data operation it performs as well as whether it is the type's default data method. In this example the NorthwindData type exposes two data methods: one to retrieve a set of data named GetAllEmployees, and another to delete data named DeleteEmployeeByID. The DataObjectMethodAttribute attribute is applied to both methods, the GetAllEmployees method is marked as the default method for the Select data operation, and the DeleteEmployeeByID method is marked as the default method for the Delete data operation.

[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

Remarks

You can use the DataObjectMethodAttribute to identify data operation methods on a type marked with the DataObjectAttribute attribute so that they are more easily identified by callers using reflection. When the DataObjectMethodAttribute attribute is applied to a method, it describes the type of operation the method performs and indicates whether the method is the default data operation method of a type. Components such as the ObjectDataSource control and the ObjectDataSourceDesigner class examine the values of this attribute, if present, to help determine which data method to call at run time.

Constructors

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Initializes a new instance of the DataObjectMethodAttribute class, identifies the type of data operation the method performs, and identifies whether the method is the default data method that the data object exposes.

DataObjectMethodAttribute(DataObjectMethodType)

Initializes a new instance of the DataObjectMethodAttribute class and identifies the type of data operation the method performs.

Properties

IsDefault

Gets a value indicating whether the method that the DataObjectMethodAttribute is applied to is the default data method exposed by the data object for a specific method type.

MethodType

Gets a DataObjectMethodType value indicating the type of data operation the method performs.

TypeId

When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Methods

Equals(Object)

Returns a value indicating whether this instance is equal to a specified object.

GetHashCode()

Returns the hash code for this instance.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute()

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object)

Gets a value indicating whether this instance shares a common pattern with a specified attribute.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

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

Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from 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.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Applies to