Добрый день.
Есть XML в виде :
| Код | <billers Col1Name="Key" Col2Name="Value"> <MethodsList> <Method Name="строка вызова" type="Concatenate" ReadOnly="true" FieldName="@GMProp" Delimiter=""/> </MethodsList> <FieldsList> <Field label="ServiceId" Type="Целое число" IsObligatory="true" Visible="false" Value="294" MethodName="строка вызова" Long="12"/> <Field label="@Prop" Visible="false" Value="msisdn=38" MethodName="строка вызова"/> <Field label="Телефон" IsObligatory="true" Value="044" MethodName="строка вызова" Stored="F1" FinderID="true" Long="10"/> <Field label="ФИО" Type="ФИО" Stored="F2"/> <Field label="@GMProp" ReadOnly="true" Visible="false"/> <Field label="Сумма пополнения" Type="Дробное число" IsObligatory="true" Summable="true" Long="10,2"/> <Field label="@доп" ReadOnly="true" Visible="false" Value="; " MethodName="строка вызова"/> </FieldsList> </billers>
|
Нужно ее десериолизовать.
Делаю так:
Есть соответствующие классы :
| Код | [Serializable] [XmlRoot("billers")] public class OrganizationControl { [XmlArray("MethodsList")] [XmlArrayItem(typeof(OrganizationMethod))] public List<OrganizationMethod> GetOrganizationMethods { get; set; }
[XmlArray("FieldsList")] [XmlArrayItem(typeof(OrganizationField))] public List<OrganizationField> GetOrganizationFields { get; set; }
public OrganizationControl() { GetOrganizationMethods = new List<OrganizationMethod>(); GetOrganizationFields = new List<OrganizationField>(); } }
[Serializable] [XmlRoot("Field")] public class OrganizationField { [XmlAttribute("label")] public string Name { get; set; } [XmlAttribute] public string Type { get; set; } [XmlAttribute] public bool IsObligatory { get; set; } [XmlAttribute] public string Value { get; set; } [XmlAttribute] public string Mask { get; set; } [XmlAttribute] public decimal Long { get; set; } [XmlAttribute] public string MethodName { get; set; }
private bool _visible = true; [XmlAttribute] public bool Visible { get { return _visible; } set { _visible = value; } }
[XmlAttribute] public bool ReadOnly { get; set; } }
[Serializable] [XmlRoot("Method")] public class OrganizationMethod { [XmlAttribute] public string Name { get; set; } [XmlAttribute("type")] public string Type { get; set; } [XmlAttribute] public bool ReadOnly { get; set; } [XmlAttribute] public string FieldName { get; set; } [XmlAttribute] public string FilterField { get; set; } [XmlAttribute] public string AddParams { get; set; } [XmlAttribute] public string Delimiter { get; set; } }
|
И класс для десериализации :
| Код | public static class Serializer<T> { public static T Deserialize(string value) { using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(value))) { XmlSerializer serializer = new XmlSerializer(typeof(T)); return (T)serializer.Deserialize(stream); } } }
|
Строчка десериализации :
| Код | OrganizationControl orgControl = Serializer<OrganizationControl>.Deserialize(xml);
|
Такая реализация не работает. Данные не десериализируются и списки Methods и Fields не заполняются.
Вопрос: что я делаю не так?
Спасибо. |