Exemplo n.º 1
0
        public static void SaveToXml(string path, DataPackageConfiguration configuration)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(DataPackageConfiguration), new Type[] {
                typeof(BoolDataFieldEntry),
                typeof(ByteDataFieldEntry),
                typeof(I16DataFieldEntry),
                typeof(I32DataFieldEntry),
                typeof(I64DataFieldEntry),
                typeof(UI16DataFieldEntry),
                typeof(UI32DataFieldEntry),
                typeof(UI64DataFieldEntry),
                typeof(Ieee754FloatDataFieldEntry),
                typeof(Ieee754DoubleDataFieldEntry),
                typeof(DateTimeDataFieldEntry),
                typeof(StringDataFieldEntry),
                typeof(BcdDataFieldEntry)
            });

            using (StreamWriter sw = new StreamWriter(path))
            {
                serializer.Serialize(sw, configuration);
                sw.Flush();
                sw.Close();
            }
        }
Exemplo n.º 2
0
        public static DataPackageConfiguration LoadFromXml(string path)
        {
            DataPackageConfiguration configuration = null;

            XmlSerializer serializer = new XmlSerializer(typeof(DataPackageConfiguration), new Type[] {
                typeof(BoolDataFieldEntry),
                typeof(ByteDataFieldEntry),
                typeof(I16DataFieldEntry),
                typeof(I32DataFieldEntry),
                typeof(I64DataFieldEntry),
                typeof(UI16DataFieldEntry),
                typeof(UI32DataFieldEntry),
                typeof(UI64DataFieldEntry),
                typeof(Ieee754FloatDataFieldEntry),
                typeof(Ieee754DoubleDataFieldEntry),
                typeof(DateTimeDataFieldEntry),
                typeof(StringDataFieldEntry),
                typeof(BcdDataFieldEntry)
            });

            using (StreamReader sr = new StreamReader(path))
            {
                configuration = serializer.Deserialize(sr) as DataPackageConfiguration;
                sr.Close();
            }

            return(configuration);
        }