DataObjectAttribute Classe

Definizione

Identifica un tipo come oggetto adatto per l'associazione a un oggetto ObjectDataSource. La classe non può essere ereditata.

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
Ereditarietà
DataObjectAttribute
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come applicare l'attributo per indicare che un oggetto è adatto per l'associazione DataObjectAttribute a un ObjectDataSource oggetto . In questo esempio, l'oggetto è destinato all'uso NorthwindData con un ObjectDataSource oggetto .

[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

Commenti

Usare l'attributo DataObjectAttribute per identificare un oggetto come adatto per l'uso da parte di un ObjectDataSource oggetto . Le classi in fase di progettazione, ad esempio la ObjectDataSourceDesigner classe , usano l'attributo DataObjectAttribute per presentare oggetti adatti da associare a un ObjectDataSource oggetto .

Per altre informazioni sull'uso degli attributi, vedere Attributi.

Costruttori

Nome Descrizione
DataObjectAttribute()

Inizializza una nuova istanza della classe DataObjectAttribute.

DataObjectAttribute(Boolean)

Inizializza una nuova istanza della DataObjectAttribute classe e indica se un oggetto è adatto per l'associazione a un ObjectDataSource oggetto.

Campi

Nome Descrizione
DataObject

Indica che la classe è adatta per l'associazione a un ObjectDataSource oggetto in fase di progettazione. Questo campo è di sola lettura.

Default

Rappresenta il valore predefinito della DataObjectAttribute classe , che indica che la classe è adatta per l'associazione a un ObjectDataSource oggetto in fase di progettazione. Questo campo è di sola lettura.

NonDataObject

Indica che la classe non è adatta per l'associazione a un ObjectDataSource oggetto in fase di progettazione. Questo campo è di sola lettura.

Proprietà

Nome Descrizione
IsDataObject

Ottiene un valore che indica se un oggetto deve essere considerato adatto per l'associazione a un ObjectDataSource oggetto in fase di progettazione.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Determina se questa istanza di DataObjectAttribute corrisponde al modello di un altro oggetto.

GetHashCode()

Restituisce il codice hash per questa istanza.

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Ottiene un valore che indica se il valore corrente dell'attributo è il valore predefinito per l'attributo.

Match(Object)

Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da Attribute)

Si applica a