Share via


XmlAttributeOverrides.Item[] Özellik

Tanım

Geçersiz kılma öznitelikleri koleksiyonunu temsil eden bir nesnesi alır.

Aşırı Yüklemeler

Item[Type]

Belirtilen, temel sınıf türüyle ilişkili nesneyi alır.

Item[Type, String]

Belirtilen (temel sınıf) türüyle ilişkili nesneyi alır. member parametresi geçersiz kılınan temel sınıf üyesini belirtir.

Item[Type]

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

Belirtilen, temel sınıf türüyle ilişkili nesneyi alır.

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

Parametreler

type
Type

Almak istediğiniz öznitelik koleksiyonuyla ilişkili temel sınıf Type .

Özellik Değeri

XmlAttributes Geçersiz kılma öznitelikleri koleksiyonunu temsil eden bir.

Örnekler

Aşağıdaki örnek bir XmlAttributeOverrides nesne, bir XmlAttributes nesne ve bir XmlRootAttribute nesne oluşturur. Örnek, nesnesinin XmlRoot özelliğine XmlAttributes öğesini atar XmlRootAttribute ve nesnesini nesnesine XmlAttributeOverrides eklerXmlAttributes. Son olarak, örnek serileştirilmiş sınıfın XmlAttributeOverrides nesnesini geçirerek Type nesnesini alırXmlAttributes. Bu örnekte , Type şeklindedir Group.

// This is the class that will be serialized.
public ref class Group
{
public:
   String^ GroupName;

   [XmlAttributeAttribute]
   int GroupCode;
};

public ref class Sample
{
public:
   XmlSerializer^ CreateOverrider()
   {
      // Create an XmlSerializer with overriding attributes.
      XmlAttributes^ attrs = gcnew XmlAttributes;
      XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;
      XmlRootAttribute^ xRoot = gcnew 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( Group::typeid, attrs );

      // Get the XmlAttributes object, based on the type.
      XmlAttributes^ tempAttrs;
      tempAttrs = xOver[ Group::typeid ];

      // Print the Namespace and ElementName of the root.
      Console::WriteLine( tempAttrs->XmlRoot->Namespace );
      Console::WriteLine( tempAttrs->XmlRoot->ElementName );
      XmlSerializer^ xSer = gcnew XmlSerializer( Group::typeid,xOver );
      return xSer;
   }
};
// 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

Açıklamalar

Bir veya XmlTypeAttribute nesnesinin özniteliklerini içeren bir XmlAttributes nesneyi döndürmek için XmlRootAttribute bu aşırı yüklemeyi kullanın.

XmlAttributes Nesne, bir XmlArrayAttribute, , XmlArrayItemAttribute, XmlElementAttributeXmlEnumAttributeveya XmlAttributeAttributegeçersiz kılan nesneler içeriyorsa, geçersiz kılınan üyeyi ve türünü belirten aşırı yüklemeyi kullanmanız gerekir.

Ayrıca bkz.

Şunlara uygulanır

Item[Type, String]

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

Belirtilen (temel sınıf) türüyle ilişkili nesneyi alır. member parametresi geçersiz kılınan temel sınıf üyesini belirtir.

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

Parametreler

type
Type

İstediğiniz öznitelik koleksiyonuyla ilişkili temel sınıf Type .

member
String

Döndürülecek öğesini belirten geçersiz kılınan üyenin XmlAttributes adı.

Özellik Değeri

XmlAttributes Geçersiz kılma öznitelikleri koleksiyonunu temsil eden bir.

Örnekler

Aşağıdaki örnek bir XmlAttributeOverrides nesnesi, bir XmlAttributesve nesnesi XmlAttributeAttribute oluşturur. Örnek, nesnesinin XmlAttribute özelliğine XmlAttributes öğesini atar XmlAttributeAttribute ve nesnesini nesnesine XmlAttributeOverrides eklerXmlAttributes. Son olarak, örnek serileştirilmiş sınıfın XmlAttributes ve üye adının nesnesine XmlAttributeOverrides geçirilerek Type nesnesini alır.

// This is the class that will be serialized.
public ref class Group
{
public:
   String^ GroupName;

   [XmlAttributeAttribute]
   int GroupCode;
};

public ref class Sample
{
public:
   XmlSerializer^ CreateOverrider()
   {
      // Create an XmlSerializer with overriding attributes.
      XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;

      /* Create an XmlAttributeAttribute object and set the 
            AttributeName property. */
      XmlAttributeAttribute^ xAtt = gcnew XmlAttributeAttribute;
      xAtt->AttributeName = "Code";

      /* Create a new XmlAttributes object and set the 
            XmlAttributeAttribute object to the XmlAttribute property. */
      XmlAttributes^ attrs = gcnew XmlAttributes;
      attrs->XmlAttribute = xAtt;

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

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

      // Create the XmlSerializer instance and return it.
      XmlSerializer^ xSer = gcnew XmlSerializer( Group::typeid,xOver );
      return xSer;
   }
};
// 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

Açıklamalar

, , XmlAttributeAttributeXmlArrayItemAttribute, XmlElementAttributeveya XmlEnumAttributegeçersiz kılan nesneler içeren bir XmlAttributesXmlArrayAttributenesne döndürmek için bu aşırı yüklemeyi kullanın. XmlAttributes Nesne bir XmlRootAttribute veya XmlTypeAttributeiçeriyorsa, yalnızca geçersiz kılınan türü belirten aşırı yüklemeyi kullanmanız gerekir.

Ayrıca bkz.

Şunlara uygulanır