MapContainer.Load C# (CSharp) Метод

Load() публичный статический Метод

public static Load ( string path ) : Partition,
path string
Результат Partition,
    public static Partition Load(string path)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Partition));
        using (FileStream stream = new FileStream(path, FileMode.Open))
        {
            string spPattern = "sp";
            if( Regex.IsMatch(path.ToLower(), spPattern)) {
                using (StreamReader reader = new StreamReader(stream, true))
                {
                    string content = reader.ReadToEnd();
                    string pattern = "&";
                    string ret = Regex.Replace(content, pattern, "and");
                    return LoadFromText(ret) as Partition;
                }
            } else {
                return serializer.Deserialize(stream) as Partition;
            }

        }
    }

Usage Example

Пример #1
0
        protected override bool LoadMap(string mapName)
        {
            mapName = Path.GetFileNameWithoutExtension(mapName);
            var path = $"maps/{mapName}.map";

            Console.Print(OutputLevel.Debug, "map", $"loading map='{path}'");

            using (var stream = Storage.OpenFile(path, FileAccess.Read))
            {
                if (stream == null)
                {
                    Console.Print(OutputLevel.Debug, "map", $"could not open map='{path}'");
                    return(false);
                }

                CurrentMap = MapContainer.Load(stream, out var error);
                if (CurrentMap == null)
                {
                    Console.Print(OutputLevel.Debug, "map", $"error with load map='{path}' ({error})");
                    return(false);
                }
                CurrentMap.MapName = mapName;
                Console.Print(OutputLevel.Debug, "map", $"successful load map='{path}' ({error})");

                return(true);
            }
        }
All Usage Examples Of MapContainer::Load