ITypedList Interfész
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lehetővé teszi a köthető listák sémájának felderítését, ahol a kötéshez elérhető tulajdonságok eltérnek a kötéshez használt objektum nyilvános tulajdonságaitól.
public interface class ITypedList
public interface ITypedList
type ITypedList = interface
Public Interface ITypedList
- Származtatott
Példák
Az alábbi példakód bemutatja, hogyan implementálhatja a ITypedList felületet. A névvel ellátott SortableBindingList általános típus az BindingList<T> osztályból származik, és implementálja az interfészt ITypedList . A teljes kódlistát az ITypedList-felület implementálása című témakörben találhatja meg.
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace ITypedListCS;
[Serializable()]
public class SortableBindingList<T> : BindingList<T>, ITypedList
{
[NonSerialized()]
readonly PropertyDescriptorCollection properties;
public SortableBindingList() : base()
{
// Get the 'shape' of the list.
// Only get the public properties marked with Browsable = true.
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(
typeof(T),
[new BrowsableAttribute(true)]);
// Sort the properties.
properties = pdc.Sort();
}
#region ITypedList Implementation
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection pdc;
if (listAccessors != null && listAccessors.Length > 0)
{
// Return child list shape.
pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
}
else
{
// Return properties in sort order.
pdc = properties;
}
return pdc;
}
// This method is only used in the design-time framework
// and by the obsolete DataGrid control.
public string GetListName(PropertyDescriptor[] listAccessors) => typeof(T).Name;
#endregion
}
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Windows.Forms
<Serializable()> _
Public Class SortableBindingList(Of Tkey)
Inherits BindingList(Of Tkey)
Implements ITypedList
<NonSerialized()> _
Private properties As PropertyDescriptorCollection
Public Sub New()
MyBase.New()
' Get the 'shape' of the list.
' Only get the public properties marked with Browsable = true.
Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(Tkey), New Attribute() {New BrowsableAttribute(True)})
' Sort the properties.
properties = pdc.Sort()
End Sub
#Region "ITypedList Implementation"
Public Function GetItemProperties(ByVal listAccessors() As System.ComponentModel.PropertyDescriptor) As System.ComponentModel.PropertyDescriptorCollection Implements System.ComponentModel.ITypedList.GetItemProperties
Dim pdc As PropertyDescriptorCollection
If (Not (listAccessors Is Nothing)) And (listAccessors.Length > 0) Then
' Return child list shape
pdc = ListBindingHelper.GetListItemProperties(listAccessors(0).PropertyType)
Else
' Return properties in sort order
pdc = properties
End If
Return pdc
End Function
' This method is only used in the design-time framework
' and by the obsolete DataGrid control.
Public Function GetListName( _
ByVal listAccessors() As PropertyDescriptor) As String _
Implements System.ComponentModel.ITypedList.GetListName
Return GetType(Tkey).Name
End Function
#End Region
End Class
Megjegyzések
Ezt a felületet akkor használja, ha például egy DataView táblát customer jelképező objektumot használ, az objektum azon tulajdonságaihoz customer szeretne kapcsolódni, amelyet az DataView adott objektum képvisel, nem pedig a DataViewtulajdonságokhoz.
Ez a felület nem szükséges a köthető listák tervezési idejének támogatásához.
Az adatokhoz való kötés futásidőben vagy tervezőben is előfordulhat, de mindkettőre vannak szabályok. Futásidőben az adatokhoz az alábbi lehetőségek közül választhat:
Implementátora IList, feltéve, hogy a megvalósító rendelkezik egy erősen gépelt Item[] tulajdonság (azaz a Type minden, de Object). Ezt úgy teheti meg, hogy az alapértelmezett privát implementációt hajtja Item[] végre. Ha olyan gyűjteményt IList szeretne létrehozni, amely egy erősen beírt gyűjtemény szabályait követi, akkor a következőből CollectionBasekell származnia.
Implementátora.ITypedList
A tervezőkben ugyanazokat a szabályokat követve inicializálhatja az objektumokhoz Component való kötést.
További információ az adatforráshoz való kötésről: System.Windows.Forms.Binding osztály.
Metódusok
| Name | Description |
|---|---|
| GetItemProperties(PropertyDescriptor[]) |
PropertyDescriptorCollection Az adatok kötéséhez használt egyes elemek tulajdonságait képviselő tulajdonságokat adja vissza. |
| GetListName(PropertyDescriptor[]) |
A lista nevét adja vissza. |