У меня есть файл класса RawData.cs .
using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;
namespace ABC
{
[DataContract]
public class RawData
{
public int xX, yY;
[DataMember]
[XmlElement("IsValid")]
public bool IsValid { get; set; }
[DataMember]
[XmlElement("Pressure")]
public int Pressure { get; set; }
[DataMember]
[XmlElement("Timestamp")]
public DateTime Timestamp { get; set; }
[DataMember]
[XmlElement("X")]
public int X
{
get { return xX; }
set { xX = value; }
}
[DataMember]
[XmlElement("Y")]
public int Y
{
get { return yY; }
set { yY = value; }
}
public RawData(bool isvalid, int pressure, DateTime timestamp, int x, int y)
{
IsValid = isvalid;
Pressure = pressure;
Timestamp = timestamp;
X = x;
Y = y;
}
}
}
И я использую этот метод для десериализации файла XML в объект класса.
public static async Task<T> ReadObjectFromXmlFileAsync<T>(string filename)
{
// this reads XML content from a file ("filename") and returns an object from the XML
T objectFromXml = default(T);
var serializer = new XmlSerializer(typeof(T));
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file = await folder.GetFileAsync(filename);
Stream stream = await file.OpenStreamForReadAsync();
objectFromXml = (T)serializer.Deserialize(stream);
stream.Dispose();
return objectFromXml;
}
После этой строки var serializer = new XmlSerializer (typeof (T));
И я вызываю функцию десериализации, используя
ReadObjectFromXmlFileAsync<SmartPadPoint>(FILE_NAME_WITH_PATH);
Определение SmartPadPoint
using System;
namespace XXXXX.Devices
{
//
// Summary:
// A raw input point produced by a XXXXX SmartPad device.
public struct SmartPadPoint
{
//
// Summary:
// X coordinate of the point (in device units).
public ushort X { get; }
//
// Summary:
// Y coordinate of the point (in device units).
public ushort Y { get; }
//
// Summary:
// Pressure value.
public ushort Pressure { get; }
//
// Summary:
// Point timestamp.
public DateTime Timestamp { get; }
//
// Summary:
// Specifies whether the current point is valid.
public bool IsValid { get; }
}
}
Я получаю сообщение об исключении как Невозможно десериализовать тип 'XXXX.Devices.SmartPadPoint', поскольку он содержит свойство 'X', для которого нет общедоступного установщика.
Я пыталсяс этой ссылки, но не удалось. Нужна помощь