示例#1
0
        public static Settings FromFile(string filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }
            if (!Common.FileExists(filename))
            {
                throw new FileNotFoundException(nameof(filename));
            }

            string   contents = Common.ReadTextFile(@filename);
            Settings ret      = Common.DeserializeJson <Settings>(contents);

            return(ret);
        }
示例#2
0
        public static T CopyObject <T>(T source)
        {
            if (source == null)
            {
                return(default(T));
            }

            string json = SerializeJson(source);

            try
            {
                return(Common.DeserializeJson <T>(json));
            }
            catch (Exception)
            {
                return(default(T));
            }
        }
示例#3
0
 /// <summary>
 /// Load settings from file.
 /// </summary>
 /// <param name="filename">Filename and path.</param>
 /// <returns>Settings.</returns>
 public static Settings FromFile(string filename)
 {
     return(Common.DeserializeJson <Settings>(Common.ReadTextFile(filename)));
 }