XmlAttributeOverrides.Item[] Propriedade

Definição

Obtém um objeto que representa a coleção de atributos sobrepostos.

Sobrecargas

Name Description
Item[Type]

Obtém o objeto associado ao tipo de classe base especificado.

Item[Type, String]

Obtém o objeto associado ao tipo especificado (de classe base). O parâmetro membro especifica o membro da classe base que é sobreposto.

Item[Type]

Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs

Obtém o objeto associado ao tipo de classe base especificado.

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

A classe Type base associada à coleção de atributos que queres recuperar.

Valor de Propriedade

Um XmlAttributes que representa a coleção de atributos predominantes.

Exemplos

O exemplo seguinte cria um XmlAttributeOverrides objeto, um XmlAttributes objeto e um XmlRootAttribute objeto. O exemplo atribui o XmlRootAttribute à propriedade do XmlRoot objeto e adiciona o XmlAttributes objeto ao objeto XmlAttributesXmlAttributeOverrides. Por fim, o exemplo obtém o XmlAttributes objeto ao passar o Type da classe serializada para o XmlAttributeOverrides objeto. Neste exemplo, o Type é 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

Observações

Use esta sobrecarga para devolver um XmlAttributes objeto que contenha atributos para um XmlRootAttribute objeto ou XmlTypeAttribute .

Se o XmlAttributes objeto contiver objetos que sobrescrevam um XmlArrayAttribute, XmlArrayItemAttribute, XmlElementAttribute, XmlEnumAttribute, ou XmlAttributeAttribute, deve usar a sobrecarga que especifica o elemento sobrescrito, bem como o tipo.

Ver também

Aplica-se a

Item[Type, String]

Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs
Origem:
XmlAttributeOverrides.cs

Obtém o objeto associado ao tipo especificado (de classe base). O parâmetro membro especifica o membro da classe base que é sobreposto.

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

A classe Type base associada à coleção de atributos que queres.

member
String

O nome do membro sobreposto que especifica o XmlAttributes a devolver.

Valor de Propriedade

Um XmlAttributes que representa a coleção de atributos predominantes.

Exemplos

O exemplo seguinte cria um XmlAttributeOverrides objeto, um XmlAttributes, e um XmlAttributeAttribute objeto. O exemplo atribui o XmlAttributeAttribute à propriedade do XmlAttribute objeto e adiciona o XmlAttributes objeto ao objeto XmlAttributesXmlAttributeOverrides. Por fim, o exemplo obtém o XmlAttributes objeto ao passar o Type nome da classe serializada e do membro ao 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

Observações

Use esta sobrecarga para devolver um XmlAttributes objeto que contenha objetos que sobrescrevem um XmlArrayAttribute, XmlArrayItemAttribute, XmlAttributeAttribute, XmlElementAttribute, ou XmlEnumAttribute. Se o XmlAttributes objeto contiver um XmlRootAttribute ou XmlTypeAttribute, deve usar a sobrecarga que especifica apenas o tipo sobreposto.

Ver também

Aplica-se a