コード例 #1
0
        public static StaticSerialisationResult Deserialize(Type staticClass, string fileName)
        {
            StaticSerialisationResult SSR = new StaticSerialisationResult();

            XmlReader xmlReader = null;

            try
            {
                xmlReader = new XmlTextReader(fileName);

                Deserialize(staticClass, xmlReader);

                SSR.Successful = true;
                return(SSR);
            }
            catch (Exception ex)
            {
                SSR.Successful = false;
                SSR.Message    = ex.Message;
                return(SSR);
            }
            finally
            {
                if (xmlReader != null)
                {
                    xmlReader.Close();
                    xmlReader = null;
                }
            }
        }
コード例 #2
0
        public static StaticSerialisationResult Serialize(Type staticClass, string fileName)
        {
            XmlTextWriter             xmlWriter = null;
            StaticSerialisationResult SSR       = new StaticSerialisationResult();

            try
            {
                xmlWriter = new XmlTextWriter(fileName, null);

                xmlWriter.Formatting = Formatting.Indented;

                xmlWriter.WriteStartDocument();

                Serialize(staticClass, xmlWriter);

                xmlWriter.WriteEndDocument();

                SSR.Successful = true;

                return(SSR);
            }
            catch (Exception ex)
            {
                SSR.Message    = ex.Message;
                SSR.Successful = false;
                return(SSR);
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Flush();
                    xmlWriter.Close();
                }
            }
        }