2016-05-31 6 views
0

私が作成しているようなクラス:デシリアライズ、間違った値

[XmlRoot(ElementName = "Control", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument"),Serializable] 
    public class ControlStencilXML 
    { 
     [XmlAttribute("ReferenceName")] 
     public string ReferenceName; 
     [XmlAttribute("DisplayName")] 
     public string DisplayName; 
     [XmlAttribute("Revision")] 
     public int Revision; 
     [XmlAttribute("IsBackground")] 
     public bool IsBackground; 
     [XmlAttribute("DefaultInsertionPoint")] 
     public string DefaultInsertionPoint; 
     [XmlAttribute("IsAnimated")] 
     public bool IsAnimated; 
     [XmlAttribute("KeyWords")] 
     public string KeyWords; 
     [XmlAttribute("ToolTip")] 
     public string ToolTip; 
     [XmlElement("ShapeLayouts")] 
     public List<ShapeLayout> ShapeLayouts; 
    } 

[XmlRoot(ElementName = "ShapeLayout", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")] 
public class ShapeLayout 
{ 
    [XmlAttribute("Name")] 
    string Name; 
    [XmlAttribute("HorizontalAlignment")] 
    string HorizontalAlignment; 
    [XmlAttribute("VerticalAlignment")] 
    string VerticalAlignment; 
} 

XLM私はデシリアライズしたい:

<?xml version="1.0" encoding="utf-8"?> 
<Control ReferenceName="System.Storyboarding.Common.CheckBoxChecked" DisplayName="Checkbox (checked)" ToolTip="Checked checkbox with a text label" Revision="1" IsBackground="false" DefaultInsertionPoint="Default" Keywords="Toggle, Phone" IsAnimated="false" xmlns="http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument"> 
    <ShapeLayouts> 
    <ShapeLayout Name="Check" HorizontalAlignment="Left" VerticalAlignment="Center" /> 
    <ShapeLayout Name="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Center" /> 
    <ShapeLayout Name="Content" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    </ShapeLayouts> 
</Control> 

私は、問題をデシリアライズしようとしているときにエラーはありません最初のShapeLayoutオブジェクトだけを取得していて、その値はすべてnullに等しいということです。私はどこで間違いを犯したのですか?それを修正するには?

答えて

1

あなたが提供XMLに準拠するために、1つ以上のラッパーオブジェクトが必要になります -

[XmlRoot(ElementName = "ShapeLayouts", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")] 
public class ShapeLayouts 
{ 
    [XmlElement(ElementName = "ShapeLayout", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")] 
    public List<ShapeLayout> ShapeLayout { get; set; } 
} 
+0

が働いて、どうもありがとうございました。私はShapeLayoutフィールドの可視性も一般に変更しました。 – buks

関連する問題