Пример #1
0
        public static T ProtoLoad <T>(string path)
        {
            if (!FileTools.PrepareLoad(path))
            {
                return(default(T));
            }

            var loadedObject = default(T);

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                try { loadedObject = ProtoBuf.Serializer.Deserialize <T>(stream); }
                catch { Logger.CardinalMessage("Failed to load data from {0}.", path); }
            }

            return(loadedObject);
        }
Пример #2
0
        public static T YamlLoad <T>(string path)
        {
            if (!FileTools.PrepareLoad(path))
            {
                return(default(T));
            }

            var loadedObject = default(T);

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (var reader = new StreamReader(stream))
                {
                    try { loadedObject = yamlDeserializer.Deserialize <T>(reader); }
                    catch (Exception e)
                    {
                        Logger.CardinalMessage("Failed to load data from {0}.", path);
                        Logger.CardinalMessage(e.ToString());
                    }
                }

            return(loadedObject);
        }