DataObjectAttribute Classe

Definizione

Identifica un tipo come un 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 per identificare un oggetto come adatto per l'uso DataObjectAttribute da parte di un ObjectDataSource oggetto. Classi in fase di progettazione, ad esempio la classe, usano l'attributo ObjectDataSourceDesignerDataObjectAttribute per presentare oggetti adatti da associare a un ObjectDataSource oggetto.

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

Costruttori

DataObjectAttribute()

Inizializza una nuova istanza della classe DataObjectAttribute.

DataObjectAttribute(Boolean)

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

Campi

DataObject

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

Default

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

NonDataObject

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

Proprietà

IsDataObject

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

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

Equals(Object)

Determina se questa istanza dell'oggetto DataObjectAttribute corrisponde allo schema di un altro oggetto.

GetHashCode()

Restituisce il codice hash per l'istanza.

GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

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

Match(Object)

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

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

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

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

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle 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 a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a