Beispiel #1
0
        public void NickNameWrite(string NickName)
        {
            var p = new NickInfo();

            p.Nickname = NickName;
            if (p != null)
            {
                using (FileStream fs = new FileStream("NickInfo.json", FileMode.Create))
                {
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(NickInfo));
                    jsonFormatter.WriteObject(fs, p);
                }
            }
            else
            {
                using (FileStream fs = new FileStream("NickInfo.json", FileMode.Create))
                {
                    p = new NickInfo {
                        Nickname = ""
                    };
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(NickInfo));
                    jsonFormatter.WriteObject(fs, p);
                }
            }
        }
Beispiel #2
0
        public string NickNameRead()
        {
            var p = new NickInfo();

            using (FileStream fs = new FileStream("NickInfo.json", FileMode.OpenOrCreate))
            {
                DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(NickInfo));
                if (fs.Length != 0)
                {
                    p = (NickInfo)jsonFormatter.ReadObject(fs);
                }
            }

            return(p.Nickname);
        }