Esempio n. 1
0
        SaveAsync
        (
            string format = "json"
        )
        {
            string content = null;

            switch (format)
            {
            case "json":
            default:
                content = GoogleMavenData.SerializeToJSON_Newtonsoft(this);
                break;
            }

            string type_name = this.GetType().Name;
            string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmm");
            string filename  = $"{type_name}-{timestamp}.{format}";

            //System.IO.File.WriteAllText(filename, content);
            using (System.IO.StreamWriter writer = System.IO.File.CreateText(filename))
            {
                await writer.WriteAsync(content);
            }

            return;
        }
        public static string SerializeToXML(string filename, GoogleMavenData GoogleMavenData)
        {
            System.Xml.Serialization.XmlSerializer xs = null;
            string content = null;

            using (System.IO.TextWriter tw = new System.IO.StringWriter())
            {
                xs = new System.Xml.Serialization.XmlSerializer(typeof(GoogleMavenData));

                xs.Serialize(tw, GoogleMavenData);
                content = tw.ToString();
            }

            return(content);
        }
        public static string SerializeToJSON_System_Text_Json(GoogleMavenData GoogleMavenData)
        {
            string content = System.Text.Json.JsonSerializer.Serialize <GoogleMavenData>
                             (
                GoogleMavenData,
                null
                             );
            string type_name = GoogleMavenData.GetType().Name;
            string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmm");
            string filename  = $"{type_name}-{timestamp}.json";

            System.IO.File.WriteAllText(filename, content);

            return(content);
        }
        public static string SerializeToJSON_Newtonsoft(GoogleMavenData GoogleMavenData)
        {
            string content = Newtonsoft.Json.JsonConvert.SerializeObject(GoogleMavenData);

            return(content);
        }