关于[]的问题!!!!!!!谢谢解答
using System;
using System.Xml.Serialization; // Does XML serializing for a class.
using System.Drawing; // Required for storing a Bitmap.
using System.IO; // Required for using Memory stream objects.
using System.ComponentModel; // Required for conversion of Bitmap objects.
namespace disc1
{
/// <summary>
/// Customer test class to demonstrate how to include custom metadata attributes in a
/// class so that it can be serialized/deserialized to/from XML.
///
/// References:
/// XML Serialization at http://samples.gotdotnet.com/:
/// http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/xmlserialization/rwobjfromxml.aspx
///
/// How do I serialize an image file as XML in .NET?
/// http://www.perfectxml.com/Answers.asp?ID=2
/// </summary>
// Set this 'Customer' class as the root node of any XML file its serialized to.
[XmlRootAttribute("Customer", Namespace="", IsNullable=false)]
public class Customer
{
private Bitmap picture;
/// <summary>
/// Default constructor for this class (required for serialization).
/// </summary>
public Customer()
{
}
// Set this 'DateTimeValue' field to be an attribute of the root node.
[XmlAttributeAttribute(DataType="date")]
public System.DateTime DateTimeValue;
// By NOT specifing any custom Metadata Attributes, fields will be created
// as an element by default.
public int CustomerID;
public string CustomerName;
public int Age;
// Set serialization to IGNORE this field (ie. not add it to the XML).
[XmlIgnoreAttribute()]
public bool CustomerPaid;
// Set serialization to IGNORE this property because the 'PictureByteArray' property
// is used instead to serialize the 'Picture' Bitmap as an array of bytes.
[XmlIgnoreAttribute()]
public Bitmap Picture
{
get { return picture; }
set { picture = value; }
}
// Serializes the 'Picture' Bitmap to XML.
[XmlElementAttribute("Picture")]
public byte[] PictureByteArray
{
get
{
if (picture != null)
{
TypeConverter BitmapConverter = TypeDescriptor.GetConverter(picture.GetType());
return (byte[]) BitmapConverter.ConvertTo(picture, typeof(byte[]));
}
else
return null;
}
set
{
if (value != null)
picture = new Bitmap(new MemoryStream(value));
else
picture = null;
}
}
// Serializes an ArrayList as a "Hobbies" array of XML elements of type string named "Hobby".
[XmlArray ("Hobbies"), XmlArrayItem("Hobby", typeof(string))]
public System.Collections.ArrayList Hobbies = new System.Collections.ArrayList();
// Serializes an ArrayList as a "EmailAddresses" array of XML elements of custom type EmailAddress named "EmailAddress".
[XmlArray ("EmailAddresses"), XmlArrayItem("EmailAddress", typeof(EmailAddress))]
public System.Collections.ArrayList EmailAddresses = new System.Collections.ArrayList();
}
}
上面是一个类经常看见方法上面有"[]"
请问以下这句话的作用是什么呢?
[XmlArray ("EmailAddresses"), XmlArrayItem("EmailAddress", typeof(EmailAddress))]
using System.Xml.Serialization; // Does XML serializing for a class.
using System.Drawing; // Required for storing a Bitmap.
using System.IO; // Required for using Memory stream objects.
using System.ComponentModel; // Required for conversion of Bitmap objects.
namespace disc1
{
/// <summary>
/// Customer test class to demonstrate how to include custom metadata attributes in a
/// class so that it can be serialized/deserialized to/from XML.
///
/// References:
/// XML Serialization at http://samples.gotdotnet.com/:
/// http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/xmlserialization/rwobjfromxml.aspx
///
/// How do I serialize an image file as XML in .NET?
/// http://www.perfectxml.com/Answers.asp?ID=2
/// </summary>
// Set this 'Customer' class as the root node of any XML file its serialized to.
[XmlRootAttribute("Customer", Namespace="", IsNullable=false)]
public class Customer
{
private Bitmap picture;
/// <summary>
/// Default constructor for this class (required for serialization).
/// </summary>
public Customer()
{
}
// Set this 'DateTimeValue' field to be an attribute of the root node.
[XmlAttributeAttribute(DataType="date")]
public System.DateTime DateTimeValue;
// By NOT specifing any custom Metadata Attributes, fields will be created
// as an element by default.
public int CustomerID;
public string CustomerName;
public int Age;
// Set serialization to IGNORE this field (ie. not add it to the XML).
[XmlIgnoreAttribute()]
public bool CustomerPaid;
// Set serialization to IGNORE this property because the 'PictureByteArray' property
// is used instead to serialize the 'Picture' Bitmap as an array of bytes.
[XmlIgnoreAttribute()]
public Bitmap Picture
{
get { return picture; }
set { picture = value; }
}
// Serializes the 'Picture' Bitmap to XML.
[XmlElementAttribute("Picture")]
public byte[] PictureByteArray
{
get
{
if (picture != null)
{
TypeConverter BitmapConverter = TypeDescriptor.GetConverter(picture.GetType());
return (byte[]) BitmapConverter.ConvertTo(picture, typeof(byte[]));
}
else
return null;
}
set
{
if (value != null)
picture = new Bitmap(new MemoryStream(value));
else
picture = null;
}
}
// Serializes an ArrayList as a "Hobbies" array of XML elements of type string named "Hobby".
[XmlArray ("Hobbies"), XmlArrayItem("Hobby", typeof(string))]
public System.Collections.ArrayList Hobbies = new System.Collections.ArrayList();
// Serializes an ArrayList as a "EmailAddresses" array of XML elements of custom type EmailAddress named "EmailAddress".
[XmlArray ("EmailAddresses"), XmlArrayItem("EmailAddress", typeof(EmailAddress))]
public System.Collections.ArrayList EmailAddresses = new System.Collections.ArrayList();
}
}
上面是一个类经常看见方法上面有"[]"
请问以下这句话的作用是什么呢?
[XmlArray ("EmailAddresses"), XmlArrayItem("EmailAddress", typeof(EmailAddress))]
...全文
相关推荐
《ABAQUS_有限元分析常见问题解答》常见问题汇总.pdf )
针对这些常见问题,文档《ABAQUS_有限元分析常见问题解答》应该会给出一系列实用的解答和指导,帮助初学者更好地掌握ABAQUS软件的使用,提高有限元分析的准确性和效率。
dataX部署以及常见问题解答
DataX 部署及常见问题解答DataX 是一款由阿里巴巴开源的数据同步工具,支持多种数据源之间的数据同步。以下是 DataX 的部署及常见问题解答。
RFPA软件常见问题与解答
#### 三、软件操作问题与解答针对不同版本的RFPA软件,以下是一些常见的操作问题及其解答:**2.1 基本分析版-RFPA2D-Basic操作问题与解答**- **问题:** 如何在RFPA2D-Basic
蓝牙问题诊断命令-win10疑难解答.zip
本篇将详细介绍如何通过CMD命令行来启动蓝牙问题的疑难解答,并提供一个便捷的批处理文件(`.bat`)方法来实现一键修复。首先,我们要了解如何在命令提示符(CMD)中运行疑难解答。
支持常见问题解答:常见问题解答,其中包含针对公众询问的常见问题的说明
总的来说,Cardano的支持常见问题解答是其生态系统的重要组成部分,它帮助用户解决问题,促进社区的健康发展。


