📄 configuration.cs
字号:
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Configuration;
namespace XmlSerializationConfig
{
/// <summary>
/// The custom configuration class. This will read the custom
/// configuration section and for each child node, return an
/// instance of the object, deserialized.
/// </summary>
public class BasicConfigurator : IConfigurationSectionHandler
{
Person[] __people = new Person[0];
public object Create(object parent,
object configContext,
System.Xml.XmlNode section)
{
XmlNodeList nodes = section.SelectNodes("//Person");
for(int i=0; i<nodes.Count; i++)
{
XmlNodeReader rdr = new XmlNodeReader(nodes[i]);
XmlSerializer ser = new XmlSerializer(typeof(Person));
Person p = (Person)ser.Deserialize(rdr);
Add(p);
}
return __people;
}
/// <summary>
/// Adds a Person to the local array.
/// </summary>
/// <param name="p"></param>
void Add(Person p)
{
Person[] tmp = new Person[__people.Length+1];
Array.Copy(__people,0,tmp,0,__people.Length);
tmp[__people.Length] = p;
__people = tmp;
}
}
/// <summary>
/// The person factory, which will return the list
/// of people from the configuration file.
/// </summary>
public class PersonFactory
{
public static Person[] GetProple()
{
return (Person[])ConfigurationSettings.GetConfig("People");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -