Пример #1
0
    public static void StringDeserialize(this ConcurrentBag <Point3DCollection> bag, Stream stream)
    {
        if (bag == null)
        {
            throw new ArgumentNullException("bag");
        }

        if (stream == null)
        {
            throw new ArgumentNullException("stream");
        }

        StreamReader reader = new StreamReader(stream);
        Point3DCollectionConverter converter = new Point3DCollectionConverter();

        do
        {
            string line = reader.ReadLine();
            if (line == null)
            {
                break;
            }

            bag.Add((Point3DCollection)converter.ConvertFrom(line));

            // NOTE: could also use this:
            //bag.Add(Point3DCollection.Parse(line));
        }while (true);
    }
Пример #2
0
    public static void StringSerialize(this ConcurrentBag <Point3DCollection> bag, Stream stream)
    {
        if (bag == null)
        {
            throw new ArgumentNullException("bag");
        }

        if (stream == null)
        {
            throw new ArgumentNullException("stream");
        }

        StreamWriter writer = new StreamWriter(stream);
        Point3DCollectionConverter converter = new Point3DCollectionConverter();

        foreach (Point3DCollection coll in bag)
        {
            // we need to use the english locale as the converter needs that for parsing...
            string line = (string)converter.ConvertTo(null, CultureInfo.GetCultureInfo("en-US"), coll, typeof(string));
            writer.WriteLine(line);
        }
        writer.Flush();
    }