-3
私はそうのようなクラスを持っている:私がやりたい何C#で特定の形式でXMLをシリアル化しますか?
class Colors
{
[XmlElement("Col1")]
UIColor Col1;
[XmlElement("Col2")]
UIColor Col2;
//etc etc
}
にXMLにクラスの色をシリアライズです:そうは次のようにクラスの
[System.Serializable]
public class UIColor
{
public UIColor()
{
}
public UIColor(double red, double green, double blue, double alpha)
{
r = (float)red;
g = (float)green;
b = (float)blue;
a = (float)alpha;
}
public UIColor(double white, double alpha)
{
r = (float)white;
g = (float)white;
b = (float)white;
a = (float)alpha;
}
[System.Xml.Serialization.XmlElement("r", typeof(float))]
public float r
{
get;
set;
}
[System.Xml.Serialization.XmlElement("g", typeof(float))]
public float g
{
get;
set;
}
[System.Xml.Serialization.XmlElement("b", typeof(float))]
public float b
{
get;
set;
}
[System.Xml.Serialization.XmlElement("alpha", typeof(float))]
public float a
{
get;
set;
}
}
そして、それの多くのインスタンス次の形式:
<Color name="Col1" r="1" g="1" b="1" alpha="1"/>
<Color name="Col2" r="2" g="2" b="2" alpha="2"/>
現在、それが出てシリアライズする方法が似ている:
<Col1>
<r>1</r>
//etc etc
あなたがかもしれません[XMLAttribute](https:// msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributeattribute(v=vs.110).aspx)。 –
XmlAttributeを使用しているときに、プリミティブ型でそれらを使用する際にエラーが発生しました – tweetypi
'System.Xml.Serialization.XmlAttribute'パラメータを削除する必要があります。また、スキーマの詳細を定義して削除する必要があります。 –