关于[]的问题!!!!!!!谢谢解答

y_dong119 2008-04-15 05:51:42
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))]


...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
changjiangzhibin 2008-04-15
  • 打赏
  • 举报
回复
Attribute 属性,主要修饰类或方法等
Property 属性,类中成员变量
virusswb 2008-04-15
  • 打赏
  • 举报
回复
特性,结合反射可以实现动态初始化
attribute
fengniumaxi 2008-04-15
  • 打赏
  • 举报
回复
这是自定义属性,是指定你用的类、方法或者字段的一种属性

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧