私は2つのクラスを持っています:基本クラス名ComponentとDBComponentという名前の継承クラス
[Serializable]
public class Component
{
private string name = string.Empty;
private string description = string.Empty;
}
[Serializable]
public class DBComponent : Component
{
private List<string> spFiles = new List<string>();
// Storage Procedure Files
[XmlArrayItem("SPFile", typeof(string))]
[XmlArray("SPFiles")]
public List<string> SPFiles
{
get { return spFiles; }
set { spFiles = value; }
}
public DBComponent(string name, string description)
: base(name, description)
{ }
}
[Serializable]
public class ComponentsCollection
{
private static ComponentsCollection instance = null;
private List<Component> components = new List<Component>();
public List<Component> Components
{
get { return components; }
set
{
components = value;
}
}
public static ComponentsCollection GetInstance()
{
if (ccuInstance == null)
{
lock (lockObject)
{
if (instance == null)
PopulateComponents();
}
}
return instance;
}
private static void PopulateComponents()
{
instance = new CCUniverse();
XmlSerializer xs = new XmlSerializer(instance.GetType());
instance = xs.Deserialize(XmlReader.Create("Components.xml")) as ComponentsCollection;
}
}
}
Xml ファイルから読み書きしたい。DBComponent クラスのシリアライゼーションを実装する必要があることはわかっています。それ以外の場合は読み取れませんが、そのための簡単な記事が見つかりません。私が見つけたすべての記事は、この単純なシナリオには複雑すぎました。
Xml ファイルは次のようになります。
<?xml version="1.0" encoding="utf-8" ?>
<ComponentsCollection>
<Components>
<DBComponent Name="Tenant Historical Database" Description="Tenant Historical Database">
<SPFiles>
<SPFile>Setup\TenantHistoricalSP.sql</SPFile>
</SPFiles>
</DBComponent>
<Component Name="Agent" Description="Desktop Agent" />
</Components>
</ComponentsCollection>
この種のxmlファイルの読み方と、何を実装する必要があるかの簡単な例を教えてください。
ありがとう
_