Ejemplo n.º 1
0
        XmlValueReader GetXmlValueReaderFromNodeString(string name, string s)
        {
            var trimmed = s.Trim();
            var bytes   = Encoding.UTF8.GetBytes(trimmed);

            XmlValueReader ret;

            // Create the stream
            using (var stream = new MemoryStream(bytes))
            {
                // Create the reader
                using (var r = XmlReader.Create(stream, _readNodesReaderSettings))
                {
                    // Read the values from the stream
                    ret = new XmlValueReader(r, name, true, UseEnumNames);
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
        static IValueReader CreateReaderFromString(string data, string rootNodeName, bool?useEnumNames = null)
        {
            // Discover the format
            var format = FindContentFormatForString(data);

            Debug.Assert(EnumHelper <GenericValueIOFormat> .IsDefined(format));

            // Create the IValueReader of the needed type
            switch (format)
            {
            case GenericValueIOFormat.Binary:
                if (useEnumNames.HasValue)
                {
                    return(BinaryValueReader.CreateFromString(data, useEnumNames.Value));
                }
                else
                {
                    return(BinaryValueReader.CreateFromString(data));
                }

            case GenericValueIOFormat.Xml:
                if (useEnumNames.HasValue)
                {
                    return(XmlValueReader.CreateFromString(data, rootNodeName, useEnumNames.Value));
                }
                else
                {
                    return(XmlValueReader.CreateFromString(data, rootNodeName));
                }
            }

            const string errmsg = "Ran into unsupported format `{0}`. Format value was acquired from FindFileFormat().";

            Debug.Fail(string.Format(errmsg, format));
            throw new ArgumentException(string.Format(errmsg, format));
        }