Partekatu honen bidez:


XmlAttributeOverrides.Item[] Propiedad

Definición

Obtiene un objeto que representa la colección de atributos de invalidación.

Sobrecargas

Nombre Description
Item[Type]

Obtiene el objeto asociado al tipo especificado, clase base.

Item[Type, String]

Obtiene el objeto asociado al tipo especificado (clase base). El parámetro miembro especifica el miembro de clase base que se invalida.

Item[Type]

Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs

Obtiene el objeto asociado al tipo especificado, clase base.

public:
 property System::Xml::Serialization::XmlAttributes ^ default[Type ^] { System::Xml::Serialization::XmlAttributes ^ get(Type ^ type); };
public System.Xml.Serialization.XmlAttributes this[Type type] { get; }
public System.Xml.Serialization.XmlAttributes? this[Type type] { get; }
member this.Item(Type) : System.Xml.Serialization.XmlAttributes
Default Public ReadOnly Property Item(type As Type) As XmlAttributes

Parámetros

type
Type

Clase base Type asociada a la colección de atributos que desea recuperar.

Valor de propiedad

que XmlAttributes representa la colección de atributos de invalidación.

Ejemplos

En el ejemplo siguiente se crea un XmlAttributeOverrides objeto, un XmlAttributes objeto y un XmlRootAttribute objeto . En el ejemplo se asigna a XmlRootAttribute la XmlRoot propiedad del XmlAttributes objeto y se agrega el XmlAttributes objeto al XmlAttributeOverrides objeto . Por último, el ejemplo obtiene el XmlAttributes objeto pasando el Type de la clase serializada al XmlAttributeOverrides objeto . En este ejemplo, Type es Group.

// This is the class that will be serialized.
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Sample
{
public XmlSerializer CreateOverrider()
{
   // Create an XmlSerializer with overriding attributes.
   XmlAttributes attrs = new XmlAttributes();
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();

   XmlRootAttribute xRoot = new XmlRootAttribute();
   // Set a new Namespace and ElementName for the root element.
   xRoot.Namespace = "http://www.cpandl.com";
   xRoot.ElementName = "NewGroup";
   attrs.XmlRoot = xRoot;

   xOver.Add(typeof(Group), attrs);

   // Get the XmlAttributes object, based on the type.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group)];

   // Print the Namespace and ElementName of the root.
   Console.WriteLine(tempAttrs.XmlRoot.Namespace);
   Console.WriteLine(tempAttrs.XmlRoot.ElementName);

   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim attrs As New XmlAttributes()
        Dim xOver As New XmlAttributeOverrides()
        
        Dim xRoot As New XmlRootAttribute()
        ' Set a new Namespace and ElementName for the root element.
        xRoot.Namespace = "http://www.cpandl.com"
        xRoot.ElementName = "NewGroup"
        attrs.XmlRoot = xRoot
        
        xOver.Add(GetType(Group), attrs)
        
        ' Get the XmlAttributes object, based on the type.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group))
        
        ' Print the Namespace and ElementName of the root.
        Console.WriteLine(tempAttrs.XmlRoot.Namespace)
        Console.WriteLine(tempAttrs.XmlRoot.ElementName)
        
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

Comentarios

Use esta sobrecarga para devolver un XmlAttributes objeto que contiene atributos para un XmlRootAttribute objeto o XmlTypeAttribute .

Si el XmlAttributes objeto contiene objetos que invalidan un XmlArrayAttribute, , XmlEnumAttributeXmlArrayItemAttributeXmlElementAttribute, o XmlAttributeAttribute, debe usar la sobrecarga que especifica el miembro invalidado, así como el tipo .

Consulte también

Se aplica a

Item[Type, String]

Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs
Source:
XmlAttributeOverrides.cs

Obtiene el objeto asociado al tipo especificado (clase base). El parámetro miembro especifica el miembro de clase base que se invalida.

public:
 property System::Xml::Serialization::XmlAttributes ^ default[Type ^, System::String ^] { System::Xml::Serialization::XmlAttributes ^ get(Type ^ type, System::String ^ member); };
public System.Xml.Serialization.XmlAttributes this[Type type, string member] { get; }
public System.Xml.Serialization.XmlAttributes? this[Type type, string member] { get; }
member this.Item(Type * string) : System.Xml.Serialization.XmlAttributes
Default Public ReadOnly Property Item(type As Type, member As String) As XmlAttributes

Parámetros

type
Type

Clase base Type asociada a la colección de atributos que desea.

member
String

Nombre del miembro invalidado que especifica el XmlAttributes que se va a devolver.

Valor de propiedad

que XmlAttributes representa la colección de atributos de invalidación.

Ejemplos

En el ejemplo siguiente se crea un XmlAttributeOverrides objeto, un XmlAttributesy un XmlAttributeAttribute objeto . En el ejemplo se asigna a XmlAttributeAttribute la XmlAttribute propiedad del XmlAttributes objeto y se agrega el XmlAttributes objeto al XmlAttributeOverrides objeto . Por último, el ejemplo obtiene el XmlAttributes objeto pasando el Type de la clase serializada y el nombre de miembro al XmlAttributeOverrides objeto .

// This is the class that will be serialized.
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Sample
{
public XmlSerializer CreateOverrider()
{
   // Create an XmlSerializer with overriding attributes.
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();

   /* Create an XmlAttributeAttribute object and set the
   AttributeName property. */
   XmlAttributeAttribute xAtt = new XmlAttributeAttribute();
   xAtt.AttributeName = "Code";

   /* Create a new XmlAttributes object and set the
   XmlAttributeAttribute object to the XmlAttribute property. */
   XmlAttributes attrs = new XmlAttributes();
   attrs.XmlAttribute = xAtt;

   /* Add the XmlAttributes to the XmlAttributeOverrides object. The
   name of the overridden attribute must be specified. */
   xOver.Add(typeof(Group), "GroupCode", attrs);

   // Get the XmlAttributes object for the type and member.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group), "GroupCode"];
   Console.WriteLine(tempAttrs.XmlAttribute.AttributeName);

   // Create the XmlSerializer instance and return it.
   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim xOver As New XmlAttributeOverrides()
        
        ' Create an XmlAttributeAttribute object and set the
        ' AttributeName property. 
        Dim xAtt As New XmlAttributeAttribute()
        xAtt.AttributeName = "Code"
        
        ' Create a new XmlAttributes object and set the
        ' XmlAttributeAttribute object to the XmlAttribute property. 
        Dim attrs As New XmlAttributes()
        attrs.XmlAttribute = xAtt
        
        ' Add the XmlAttributes to the XmlAttributeOverrides object. The
        ' name of the overridden attribute must be specified. 
        xOver.Add(GetType(Group), "GroupCode", attrs)
                
        ' Get the XmlAttributes object for the type and member.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group), "GroupCode")
        Console.WriteLine(tempAttrs.XmlAttribute.AttributeName)
        
        ' Create the XmlSerializer instance and return it.
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

Comentarios

Use esta sobrecarga para devolver un XmlAttributes objeto que contiene objetos que invalidan un XmlArrayAttribute, XmlArrayItemAttribute, XmlAttributeAttribute, XmlElementAttributeo XmlEnumAttribute. Si el XmlAttributes objeto contiene o XmlRootAttributeXmlTypeAttribute, debe usar la sobrecarga que especifica solo el tipo invalidado.

Consulte también

Se aplica a