aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers.Serialization
diff options
context:
space:
mode:
authorJan Tattermusch <jtattermusch@google.com>2015-04-16 09:55:22 -0700
committerJan Tattermusch <jtattermusch@google.com>2015-04-16 09:55:22 -0700
commit84fa3e2bbc876428efd0c99700f146115a9d5162 (patch)
tree47baa5dafe3c3ab1c49fe2ca44e9f3ffd0e0b127 /csharp/src/ProtocolBuffers.Serialization
parent813d6d652d8091e9365bfbd01efb5f2ee8bdfbce (diff)
parent836a273544f55c88d8d0988ef0117cb0636707c6 (diff)
downloadprotobuf-84fa3e2bbc876428efd0c99700f146115a9d5162.tar.gz
protobuf-84fa3e2bbc876428efd0c99700f146115a9d5162.tar.bz2
protobuf-84fa3e2bbc876428efd0c99700f146115a9d5162.zip
Imported protobuf-csharp-port into csharp/ tree
Diffstat (limited to 'csharp/src/ProtocolBuffers.Serialization')
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs688
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/AbstractTextReader.cs177
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/AbstractTextWriter.cs106
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/AbstractWriter.cs507
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/DictionaryReader.cs267
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/DictionaryWriter.cs202
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/Extensions.cs213
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/Http/FormUrlEncodedReader.cs162
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs112
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs176
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/JsonFormatReader.cs262
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs541
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/JsonTextCursor.cs442
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs67
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF20.csproj104
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF35.csproj104
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET20.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET35.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET40.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.PL40.csproj95
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL20.csproj107
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL30.csproj107
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL40.csproj108
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj93
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF20.csproj104
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF35.csproj104
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET20.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET35.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET40.csproj92
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.PL40.csproj95
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL20.csproj107
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL30.csproj107
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL40.csproj108
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.csproj93
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs18
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/XmlFormatReader.cs338
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs280
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/XmlReaderOptions.cs17
-rw-r--r--csharp/src/ProtocolBuffers.Serialization/XmlWriterOptions.cs24
39 files changed, 6587 insertions, 0 deletions
diff --git a/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs b/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs
new file mode 100644
index 00000000..e198d0b0
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs
@@ -0,0 +1,688 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Google.ProtocolBuffers.Descriptors;
+
+//Disable CS3011: only CLS-compliant members can be abstract
+#pragma warning disable 3011
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Provides a base-class that provides some basic functionality for handling type dispatching
+ /// </summary>
+ public abstract class AbstractReader : ICodedInputStream
+ {
+ private const int DefaultMaxDepth = 64;
+ private int _depth;
+
+ /// <summary> Constructs a new reader </summary>
+ protected AbstractReader() { MaxDepth = DefaultMaxDepth; }
+
+ /// <summary> Gets or sets the maximum recursion depth allowed </summary>
+ public int MaxDepth { get; set; }
+
+ /// <summary>
+ /// Merges the contents of stream into the provided message builder
+ /// </summary>
+ public TBuilder Merge<TBuilder>(TBuilder builder) where TBuilder : IBuilderLite
+ {
+ return Merge(builder, ExtensionRegistry.Empty);
+ }
+
+ /// <summary>
+ /// Merges the contents of stream into the provided message builder
+ /// </summary>
+ public abstract TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
+ where TBuilder : IBuilderLite;
+
+ /// <summary>
+ /// Peeks at the next field in the input stream and returns what information is available.
+ /// </summary>
+ /// <remarks>
+ /// This may be called multiple times without actually reading the field. Only after the field
+ /// is either read, or skipped, should PeekNext return a different value.
+ /// </remarks>
+ protected abstract bool PeekNext(out string field);
+
+ /// <summary>
+ /// Causes the reader to skip past this field
+ /// </summary>
+ protected abstract void Skip();
+
+ /// <summary>
+ /// Returns true if it was able to read a Boolean from the input
+ /// </summary>
+ protected abstract bool Read(ref bool value);
+
+ /// <summary>
+ /// Returns true if it was able to read a Int32 from the input
+ /// </summary>
+ protected abstract bool Read(ref int value);
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt32 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected abstract bool Read(ref uint value);
+
+ /// <summary>
+ /// Returns true if it was able to read a Int64 from the input
+ /// </summary>
+ protected abstract bool Read(ref long value);
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt64 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected abstract bool Read(ref ulong value);
+
+ /// <summary>
+ /// Returns true if it was able to read a Single from the input
+ /// </summary>
+ protected abstract bool Read(ref float value);
+
+ /// <summary>
+ /// Returns true if it was able to read a Double from the input
+ /// </summary>
+ protected abstract bool Read(ref double value);
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected abstract bool Read(ref string value);
+
+ /// <summary>
+ /// Returns true if it was able to read a ByteString from the input
+ /// </summary>
+ protected abstract bool Read(ref ByteString value);
+
+ /// <summary>
+ /// returns true if it was able to read a single value into the value reference. The value
+ /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
+ /// </summary>
+ protected abstract bool ReadEnum(ref object value);
+
+ /// <summary>
+ /// Merges the input stream into the provided IBuilderLite
+ /// </summary>
+ protected abstract bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry);
+
+ /// <summary>
+ /// Reads the root-message preamble specific to this formatter
+ /// </summary>
+ public abstract void ReadMessageStart();
+
+ /// <summary>
+ /// Reads the root-message close specific to this formatter
+ /// </summary>
+ public abstract void ReadMessageEnd();
+
+ /// <summary>
+ /// Merges the input stream into the provided IBuilderLite
+ /// </summary>
+ public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
+ {
+ return ReadMessage(value, registry);
+ }
+
+ /// <summary>
+ /// Cursors through the array elements and stops at the end of the array
+ /// </summary>
+ protected virtual IEnumerable<string> ForeachArrayItem(string field)
+ {
+ string next = field;
+ while (true)
+ {
+ yield return next;
+
+ if (!PeekNext(out next) || next != field)
+ {
+ break;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Reads an array of T messages
+ /// </summary>
+ public virtual bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
+ ExtensionRegistry registry)
+ {
+ bool success = false;
+ foreach (string next in ForeachArrayItem(field))
+ {
+ IBuilderLite builder = messageType.WeakCreateBuilderForType();
+ if (ReadMessage(builder, registry))
+ {
+ items.Add((T) builder.WeakBuild());
+ success |= true;
+ }
+ }
+ return success;
+ }
+
+ /// <summary>
+ /// Reads an array of T messages as a proto-buffer group
+ /// </summary>
+ public virtual bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
+ ExtensionRegistry registry)
+ {
+ bool success = false;
+ foreach (string next in ForeachArrayItem(field))
+ {
+ IBuilderLite builder = messageType.WeakCreateBuilderForType();
+ if (ReadGroup(builder, registry))
+ {
+ items.Add((T) builder.WeakBuild());
+ success |= true;
+ }
+ }
+ return success;
+ }
+
+ /// <summary>
+ /// Reads an array of System.Enum type T and adds them to the collection
+ /// </summary>
+ public virtual bool ReadEnumArray(string field, ICollection<object> items)
+ {
+ bool success = false;
+ foreach (string next in ForeachArrayItem(field))
+ {
+ object temp = null;
+ if (ReadEnum(ref temp))
+ {
+ items.Add(temp);
+ success |= true;
+ }
+ }
+ return success;
+ }
+
+ /// <summary>
+ /// Reads an array of T, where T is a primitive type defined by FieldType
+ /// </summary>
+ public virtual bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
+ {
+ bool success = false;
+ foreach (string next in ForeachArrayItem(field))
+ {
+ object temp = null;
+ if (ReadField(type, ref temp))
+ {
+ items.Add((T) temp);
+ success |= true;
+ }
+ }
+ return success;
+ }
+
+ /// <summary>
+ /// returns true if it was able to read a single primitive value of FieldType into the value reference
+ /// </summary>
+ public virtual bool ReadField(FieldType type, ref object value)
+ {
+ switch (type)
+ {
+ case FieldType.Bool:
+ {
+ bool temp = false;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ case FieldType.SFixed64:
+ {
+ long temp = 0;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.UInt64:
+ case FieldType.Fixed64:
+ {
+ ulong temp = 0;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.Int32:
+ case FieldType.SInt32:
+ case FieldType.SFixed32:
+ {
+ int temp = 0;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.UInt32:
+ case FieldType.Fixed32:
+ {
+ uint temp = 0;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.Float:
+ {
+ float temp = float.NaN;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.Double:
+ {
+ double temp = float.NaN;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.String:
+ {
+ string temp = null;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ case FieldType.Bytes:
+ {
+ ByteString temp = null;
+ if (Read(ref temp))
+ {
+ value = temp;
+ }
+ else
+ {
+ return false;
+ }
+ break;
+ }
+ default:
+ throw InvalidProtocolBufferException.InvalidTag();
+ }
+ return true;
+ }
+
+ #region ICodedInputStream Members
+
+ bool ICodedInputStream.ReadTag(out uint fieldTag, out string fieldName)
+ {
+ fieldTag = 0;
+ if (PeekNext(out fieldName))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool ICodedInputStream.ReadDouble(ref double value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadFloat(ref float value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadUInt64(ref ulong value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadInt64(ref long value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadInt32(ref int value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadFixed64(ref ulong value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadFixed32(ref uint value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadBool(ref bool value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadString(ref string value)
+ {
+ return Read(ref value);
+ }
+
+ void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
+ {
+ if (_depth++ > MaxDepth)
+ {
+ throw new RecursionLimitExceededException();
+ }
+ ReadGroup(builder, extensionRegistry);
+ _depth--;
+ }
+
+ void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
+ {
+ throw new NotSupportedException();
+ }
+
+ void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
+ {
+ if (_depth++ > MaxDepth)
+ {
+ throw new RecursionLimitExceededException();
+ }
+ ReadMessage(builder, extensionRegistry);
+ _depth--;
+ }
+
+ bool ICodedInputStream.ReadBytes(ref ByteString value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadUInt32(ref uint value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
+ {
+ value = null;
+ unknown = null;
+ if (ReadEnum(ref unknown))
+ {
+ if (unknown is int)
+ {
+ value = mapping.FindValueByNumber((int) unknown);
+ }
+ else if (unknown is string)
+ {
+ value = mapping.FindValueByName((string) unknown);
+ }
+ return value != null;
+ }
+ return false;
+ }
+
+ bool ICodedInputStream.ReadEnum<T>(ref T value, out object rawValue)
+ {
+ rawValue = null;
+ if (ReadEnum(ref rawValue))
+ {
+ if (!EnumParser<T>.TryConvert(rawValue, ref value))
+ {
+ value = default(T);
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ bool ICodedInputStream.ReadSFixed32(ref int value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadSFixed64(ref long value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadSInt32(ref int value)
+ {
+ return Read(ref value);
+ }
+
+ bool ICodedInputStream.ReadSInt64(ref long value)
+ {
+ return Read(ref value);
+ }
+
+ void ICodedInputStream.ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName,
+ ICollection<object> list)
+ {
+ ReadArray(fieldType, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list,
+ out ICollection<object> unknown, IEnumLiteMap mapping)
+ {
+ unknown = null;
+ List<object> array = new List<object>();
+ if (ReadEnumArray(fieldName, array))
+ {
+ foreach (object rawValue in array)
+ {
+ IEnumLite item = null;
+ if (rawValue is int)
+ {
+ item = mapping.FindValueByNumber((int) rawValue);
+ }
+ else if (rawValue is string)
+ {
+ item = mapping.FindValueByName((string) rawValue);
+ }
+
+ if (item != null)
+ {
+ list.Add(item);
+ }
+ else
+ {
+ if (unknown == null)
+ {
+ unknown = new List<object>();
+ }
+ unknown.Add(rawValue);
+ }
+ }
+ }
+ }
+
+ void ICodedInputStream.ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list,
+ out ICollection<object> unknown)
+ {
+ unknown = null;
+ List<object> array = new List<object>();
+ if (ReadEnumArray(fieldName, array))
+ {
+ foreach (object rawValue in array)
+ {
+ T val = default(T);
+ if (EnumParser<T>.TryConvert(rawValue, ref val))
+ {
+ list.Add(val);
+ }
+ else
+ {
+ if (unknown == null)
+ {
+ unknown = new List<object>();
+ }
+ unknown.Add(rawValue);
+ }
+ }
+ }
+ }
+
+ void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
+ ExtensionRegistry registry)
+ {
+ if (_depth++ > MaxDepth)
+ {
+ throw new RecursionLimitExceededException();
+ }
+ ReadMessageArray(fieldName, list, messageType, registry);
+ _depth--;
+ }
+
+ void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
+ ExtensionRegistry registry)
+ {
+ if (_depth++ > MaxDepth)
+ {
+ throw new RecursionLimitExceededException();
+ }
+ ReadGroupArray(fieldName, list, messageType, registry);
+ _depth--;
+ }
+
+ bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
+ {
+ return ReadField(fieldType, ref value);
+ }
+
+ bool ICodedInputStream.IsAtEnd
+ {
+ get
+ {
+ string next;
+ return PeekNext(out next) == false;
+ }
+ }
+
+ bool ICodedInputStream.SkipField()
+ {
+ Skip();
+ return true;
+ }
+
+ void ICodedInputStream.ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
+ {
+ ReadArray(FieldType.String, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list)
+ {
+ ReadArray(FieldType.Bytes, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list)
+ {
+ ReadArray(FieldType.Bool, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
+ {
+ ReadArray(FieldType.Int32, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
+ {
+ ReadArray(FieldType.SInt32, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list)
+ {
+ ReadArray(FieldType.UInt32, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list)
+ {
+ ReadArray(FieldType.Fixed32, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list)
+ {
+ ReadArray(FieldType.SFixed32, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
+ {
+ ReadArray(FieldType.Int64, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
+ {
+ ReadArray(FieldType.SInt64, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
+ {
+ ReadArray(FieldType.UInt64, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
+ {
+ ReadArray(FieldType.Fixed64, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list)
+ {
+ ReadArray(FieldType.SFixed64, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list)
+ {
+ ReadArray(FieldType.Double, fieldName, list);
+ }
+
+ void ICodedInputStream.ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list)
+ {
+ ReadArray(FieldType.Float, fieldName, list);
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/AbstractTextReader.cs b/csharp/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
new file mode 100644
index 00000000..b40a560a
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
@@ -0,0 +1,177 @@
+using System;
+using System.Globalization;
+using System.Xml;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Provides a base class for text-parsing readers
+ /// </summary>
+ public abstract class AbstractTextReader : AbstractReader
+ {
+ /// <summary> Constructs a new reader </summary>
+ protected AbstractTextReader() { }
+
+ /// <summary>
+ /// Reads a typed field as a string
+ /// </summary>
+ protected abstract bool ReadAsText(ref string textValue, Type type);
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected override bool Read(ref string value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(string)))
+ {
+ value = text;
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Boolean from the input
+ /// </summary>
+ protected override bool Read(ref bool value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(bool)))
+ {
+ value = XmlConvert.ToBoolean(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Int32 from the input
+ /// </summary>
+ protected override bool Read(ref int value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(int)))
+ {
+ value = XmlConvert.ToInt32(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt32 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override bool Read(ref uint value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(uint)))
+ {
+ value = XmlConvert.ToUInt32(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Int64 from the input
+ /// </summary>
+ protected override bool Read(ref long value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(long)))
+ {
+ value = XmlConvert.ToInt64(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt64 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override bool Read(ref ulong value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(ulong)))
+ {
+ value = XmlConvert.ToUInt64(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Single from the input
+ /// </summary>
+ protected override bool Read(ref float value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(float)))
+ {
+ value = XmlConvert.ToSingle(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Double from the input
+ /// </summary>
+ protected override bool Read(ref double value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(double)))
+ {
+ value = XmlConvert.ToDouble(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Provides decoding of bytes read from the input stream
+ /// </summary>
+ protected virtual ByteString DecodeBytes(string bytes)
+ {
+ return ByteString.FromBase64(bytes);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a ByteString from the input
+ /// </summary>
+ protected override bool Read(ref ByteString value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(ByteString)))
+ {
+ value = DecodeBytes(text);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// returns true if it was able to read a single value into the value reference. The value
+ /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
+ /// </summary>
+ protected override bool ReadEnum(ref object value)
+ {
+ string text = null;
+ if (ReadAsText(ref text, typeof(Enum)))
+ {
+ int number;
+ if (FrameworkPortability.TryParseInt32(text, NumberStyles.Integer, FrameworkPortability.InvariantCulture, out number))
+ {
+ value = number;
+ return true;
+ }
+ value = text;
+ return true;
+ }
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/AbstractTextWriter.cs b/csharp/src/ProtocolBuffers.Serialization/AbstractTextWriter.cs
new file mode 100644
index 00000000..2c778dfc
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/AbstractTextWriter.cs
@@ -0,0 +1,106 @@
+using System;
+using System.Xml;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Provides a base class for text writers
+ /// </summary>
+ public abstract class AbstractTextWriter : AbstractWriter
+ {
+ /// <summary>
+ /// Encodes raw bytes to be written to the stream
+ /// </summary>
+ protected virtual string EncodeBytes(ByteString bytes)
+ {
+ return bytes.ToBase64();
+ }
+
+ /// <summary>
+ /// Writes a typed field as a text value
+ /// </summary>
+ protected abstract void WriteAsText(string field, string textValue, object typedValue);
+
+ /// <summary>
+ /// Writes a String value
+ /// </summary>
+ protected override void Write(string field, string value)
+ {
+ WriteAsText(field, value, value);
+ }
+
+ /// <summary>
+ /// Writes a Boolean value
+ /// </summary>
+ protected override void Write(string field, bool value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a Int32 value
+ /// </summary>
+ protected override void Write(string field, int value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a UInt32 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override void Write(string field, uint value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a Int64 value
+ /// </summary>
+ protected override void Write(string field, long value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a UInt64 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override void Write(string field, ulong value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a Single value
+ /// </summary>
+ protected override void Write(string field, float value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a Double value
+ /// </summary>
+ protected override void Write(string field, double value)
+ {
+ WriteAsText(field, XmlConvert.ToString(value), value);
+ }
+
+ /// <summary>
+ /// Writes a set of bytes
+ /// </summary>
+ protected override void Write(string field, ByteString value)
+ {
+ WriteAsText(field, EncodeBytes(value), value);
+ }
+
+ /// <summary>
+ /// Writes a System.Enum by the numeric and textual value
+ /// </summary>
+ protected override void WriteEnum(string field, int number, string name)
+ {
+ WriteAsText(field, name, number);
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/AbstractWriter.cs b/csharp/src/ProtocolBuffers.Serialization/AbstractWriter.cs
new file mode 100644
index 00000000..2dc6b887
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/AbstractWriter.cs
@@ -0,0 +1,507 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using Google.ProtocolBuffers.Descriptors;
+
+//Disable CS3011: only CLS-compliant members can be abstract
+#pragma warning disable 3011
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Provides a base class for writers that performs some basic type dispatching
+ /// </summary>
+ public abstract class AbstractWriter : ICodedOutputStream
+ {
+ /// <summary>
+ /// Completes any pending write operations
+ /// </summary>
+ public virtual void Flush()
+ {
+ }
+
+ /// <summary>
+ /// Writes the message to the the formatted stream.
+ /// </summary>
+ public abstract void WriteMessage(IMessageLite message);
+
+ /// <summary>
+ /// Used to write any nessary root-message preamble. After this call you can call
+ /// IMessageLite.MergeTo(...) and complete the message with a call to WriteMessageEnd().
+ /// These three calls are identical to just calling WriteMessage(message);
+ /// </summary>
+ /// <example>
+ /// AbstractWriter writer;
+ /// writer.WriteMessageStart();
+ /// message.WriteTo(writer);
+ /// writer.WriteMessageEnd();
+ /// // ... or, but not both ...
+ /// writer.WriteMessage(message);
+ /// </example>
+ public abstract void WriteMessageStart();
+
+ /// <summary>
+ /// Used to complete a root-message previously started with a call to WriteMessageStart()
+ /// </summary>
+ public abstract void WriteMessageEnd();
+
+ /// <summary>
+ /// Writes a Boolean value
+ /// </summary>
+ protected abstract void Write(string field, Boolean value);
+
+ /// <summary>
+ /// Writes a Int32 value
+ /// </summary>
+ protected abstract void Write(string field, Int32 value);
+
+ /// <summary>
+ /// Writes a UInt32 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected abstract void Write(string field, UInt32 value);
+
+ /// <summary>
+ /// Writes a Int64 value
+ /// </summary>
+ protected abstract void Write(string field, Int64 value);
+
+ /// <summary>
+ /// Writes a UInt64 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected abstract void Write(string field, UInt64 value);
+
+ /// <summary>
+ /// Writes a Single value
+ /// </summary>
+ protected abstract void Write(string field, Single value);
+
+ /// <summary>
+ /// Writes a Double value
+ /// </summary>
+ protected abstract void Write(string field, Double value);
+
+ /// <summary>
+ /// Writes a String value
+ /// </summary>
+ protected abstract void Write(string field, String value);
+
+ /// <summary>
+ /// Writes a set of bytes
+ /// </summary>
+ protected abstract void Write(string field, ByteString value);
+
+ /// <summary>
+ /// Writes a message or group as a field
+ /// </summary>
+ protected abstract void WriteMessageOrGroup(string field, IMessageLite message);
+
+ /// <summary>
+ /// Writes a System.Enum by the numeric and textual value
+ /// </summary>
+ protected abstract void WriteEnum(string field, int number, string name);
+
+ /// <summary>
+ /// Writes a field of the type determined by field.FieldType
+ /// </summary>
+ protected virtual void WriteField(FieldType fieldType, string field, object value)
+ {
+ switch (fieldType)
+ {
+ case FieldType.Bool:
+ Write(field, (bool) value);
+ break;
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ case FieldType.SFixed64:
+ Write(field, (long) value);
+ break;
+ case FieldType.UInt64:
+ case FieldType.Fixed64:
+ Write(field, (ulong) value);
+ break;
+ case FieldType.Int32:
+ case FieldType.SInt32:
+ case FieldType.SFixed32:
+ Write(field, (int) value);
+ break;
+ case FieldType.UInt32:
+ case FieldType.Fixed32:
+ Write(field, (uint) value);
+ break;
+ case FieldType.Float:
+ Write(field, (float) value);
+ break;
+ case FieldType.Double:
+ Write(field, (double) value);
+ break;
+ case FieldType.String:
+ Write(field, (string) value);
+ break;
+ case FieldType.Bytes:
+ Write(field, (ByteString) value);
+ break;
+ case FieldType.Group:
+ WriteMessageOrGroup(field, (IMessageLite) value);
+ break;
+ case FieldType.Message:
+ WriteMessageOrGroup(field, (IMessageLite) value);
+ break;
+ case FieldType.Enum:
+ {
+ if (value is IEnumLite)
+ {
+ WriteEnum(field, ((IEnumLite) value).Number, ((IEnumLite) value).Name);
+ }
+ else if (value is IConvertible)
+ {
+ WriteEnum(field, ((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture),
+ ((IConvertible)value).ToString(FrameworkPortability.InvariantCulture));
+ }
+ else
+ {
+ throw new ArgumentException("Expected an Enum type for field " + field);
+ }
+ break;
+ }
+ default:
+ throw InvalidProtocolBufferException.InvalidTag();
+ }
+ }
+
+ /// <summary>
+ /// Writes an array of field values
+ /// </summary>
+ protected virtual void WriteArray(FieldType fieldType, string field, IEnumerable items)
+ {
+ foreach (object obj in items)
+ {
+ WriteField(fieldType, field, obj);
+ }
+ }
+
+ /// <summary>
+ /// Writes a numeric unknown field of wire type: Fixed32, Fixed64, or Variant
+ /// </summary>
+ [CLSCompliant(false)]
+ protected virtual void WriteUnknown(WireFormat.WireType wireType, int fieldNumber, ulong value)
+ {
+ }
+
+ /// <summary>
+ /// Writes an unknown field, Expect WireType of GroupStart or LengthPrefix
+ /// </summary>
+ [CLSCompliant(false)]
+ protected virtual void WriteUnknown(WireFormat.WireType wireType, int fieldNumber, ByteString value)
+ {
+ }
+
+ #region ICodedOutputStream Members
+
+ void ICodedOutputStream.WriteUnknownGroup(int fieldNumber, IMessageLite value)
+ {
+ }
+
+ void ICodedOutputStream.WriteUnknownBytes(int fieldNumber, ByteString value)
+ {
+ }
+
+ void ICodedOutputStream.WriteUnknownField(int fieldNumber, WireFormat.WireType type, ulong value)
+ {
+ }
+
+ void ICodedOutputStream.WriteMessageSetExtension(int fieldNumber, string fieldName, IMessageLite value)
+ {
+ }
+
+ void ICodedOutputStream.WriteMessageSetExtension(int fieldNumber, string fieldName, ByteString value)
+ {
+ }
+
+ void ICodedOutputStream.WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value)
+ {
+ WriteField(fieldType, fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteDouble(int fieldNumber, string fieldName, double value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteFloat(int fieldNumber, string fieldName, float value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteUInt64(int fieldNumber, string fieldName, ulong value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteInt64(int fieldNumber, string fieldName, long value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteInt32(int fieldNumber, string fieldName, int value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteFixed64(int fieldNumber, string fieldName, ulong value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteFixed32(int fieldNumber, string fieldName, uint value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteBool(int fieldNumber, string fieldName, bool value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteString(int fieldNumber, string fieldName, string value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteGroup(int fieldNumber, string fieldName, IMessageLite value)
+ {
+ WriteMessageOrGroup(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteMessage(int fieldNumber, string fieldName, IMessageLite value)
+ {
+ WriteMessageOrGroup(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteBytes(int fieldNumber, string fieldName, ByteString value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteUInt32(int fieldNumber, string fieldName, uint value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteEnum(int fieldNumber, string fieldName, int value, object rawValue)
+ {
+ WriteEnum(fieldName, value, rawValue.ToString());
+ }
+
+ void ICodedOutputStream.WriteSFixed32(int fieldNumber, string fieldName, int value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteSFixed64(int fieldNumber, string fieldName, long value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteSInt32(int fieldNumber, string fieldName, int value)
+ {
+ Write(fieldName, value);
+ }
+
+ void ICodedOutputStream.WriteSInt64(int fieldNumber, string fieldName, long value)
+ {
+ Write(fieldName, value);
+ }
+
+
+ void ICodedOutputStream.WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list)
+ {
+ WriteArray(fieldType, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteGroupArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
+ {
+ WriteArray(FieldType.Group, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteMessageArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
+ {
+ WriteArray(FieldType.Message, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteStringArray(int fieldNumber, string fieldName, IEnumerable<string> list)
+ {
+ WriteArray(FieldType.String, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteBytesArray(int fieldNumber, string fieldName, IEnumerable<ByteString> list)
+ {
+ WriteArray(FieldType.Bytes, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteBoolArray(int fieldNumber, string fieldName, IEnumerable<bool> list)
+ {
+ WriteArray(FieldType.Bool, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteInt32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
+ {
+ WriteArray(FieldType.Int32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteSInt32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
+ {
+ WriteArray(FieldType.SInt32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteUInt32Array(int fieldNumber, string fieldName, IEnumerable<uint> list)
+ {
+ WriteArray(FieldType.UInt32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteFixed32Array(int fieldNumber, string fieldName, IEnumerable<uint> list)
+ {
+ WriteArray(FieldType.Fixed32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteSFixed32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
+ {
+ WriteArray(FieldType.SFixed32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteInt64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
+ {
+ WriteArray(FieldType.Int64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteSInt64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
+ {
+ WriteArray(FieldType.SInt64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteUInt64Array(int fieldNumber, string fieldName, IEnumerable<ulong> list)
+ {
+ WriteArray(FieldType.UInt64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteFixed64Array(int fieldNumber, string fieldName, IEnumerable<ulong> list)
+ {
+ WriteArray(FieldType.Fixed64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteSFixed64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
+ {
+ WriteArray(FieldType.SFixed64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteDoubleArray(int fieldNumber, string fieldName, IEnumerable<double> list)
+ {
+ WriteArray(FieldType.Double, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteFloatArray(int fieldNumber, string fieldName, IEnumerable<float> list)
+ {
+ WriteArray(FieldType.Float, fieldName, list);
+ }
+
+ void ICodedOutputStream.WriteEnumArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
+ {
+ WriteArray(FieldType.Enum, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName,
+ IEnumerable list)
+ {
+ WriteArray(fieldType, fieldName, list);
+ }
+
+
+ void ICodedOutputStream.WritePackedBoolArray(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<bool> list)
+ {
+ WriteArray(FieldType.Bool, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedInt32Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<int> list)
+ {
+ WriteArray(FieldType.Int32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedSInt32Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<int> list)
+ {
+ WriteArray(FieldType.SInt32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedUInt32Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<uint> list)
+ {
+ WriteArray(FieldType.UInt32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedFixed32Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<uint> list)
+ {
+ WriteArray(FieldType.Fixed32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedSFixed32Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<int> list)
+ {
+ WriteArray(FieldType.SFixed32, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedInt64Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<long> list)
+ {
+ WriteArray(FieldType.Int64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedSInt64Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<long> list)
+ {
+ WriteArray(FieldType.SInt64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedUInt64Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<ulong> list)
+ {
+ WriteArray(FieldType.UInt64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedFixed64Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<ulong> list)
+ {
+ WriteArray(FieldType.Fixed64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedSFixed64Array(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<long> list)
+ {
+ WriteArray(FieldType.SFixed64, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedDoubleArray(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<double> list)
+ {
+ WriteArray(FieldType.Double, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedFloatArray(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<float> list)
+ {
+ WriteArray(FieldType.Float, fieldName, list);
+ }
+
+ void ICodedOutputStream.WritePackedEnumArray<T>(int fieldNumber, string fieldName, int computedSize,
+ IEnumerable<T> list)
+ {
+ WriteArray(FieldType.Enum, fieldName, list);
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/DictionaryReader.cs b/csharp/src/ProtocolBuffers.Serialization/DictionaryReader.cs
new file mode 100644
index 00000000..c460523c
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/DictionaryReader.cs
@@ -0,0 +1,267 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Google.ProtocolBuffers.Descriptors;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Allows reading messages from a name/value dictionary
+ /// </summary>
+ public class DictionaryReader : AbstractReader
+ {
+ private readonly IEnumerator<KeyValuePair<string, object>> _input;
+ private bool _ready;
+
+ /// <summary>
+ /// Creates a dictionary reader from an enumeration of KeyValuePair data, like an IDictionary
+ /// </summary>
+ public DictionaryReader(IEnumerable<KeyValuePair<string, object>> input)
+ {
+ _input = input.GetEnumerator();
+ _ready = _input.MoveNext();
+ }
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void ReadMessageStart()
+ { }
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void ReadMessageEnd()
+ { }
+
+ /// <summary>
+ /// Merges the contents of stream into the provided message builder
+ /// </summary>
+ public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
+ {
+ builder.WeakMergeFrom(this, registry);
+ return builder;
+ }
+
+ /// <summary>
+ /// Peeks at the next field in the input stream and returns what information is available.
+ /// </summary>
+ /// <remarks>
+ /// This may be called multiple times without actually reading the field. Only after the field
+ /// is either read, or skipped, should PeekNext return a different value.
+ /// </remarks>
+ protected override bool PeekNext(out string field)
+ {
+ field = _ready ? _input.Current.Key : null;
+ return _ready;
+ }
+
+ /// <summary>
+ /// Causes the reader to skip past this field
+ /// </summary>
+ protected override void Skip()
+ {
+ _ready = _input.MoveNext();
+ }
+
+ private bool GetValue<T>(ref T value)
+ {
+ if (!_ready)
+ {
+ return false;
+ }
+
+ object obj = _input.Current.Value;
+ if (obj is T)
+ {
+ value = (T) obj;
+ }
+ else
+ {
+ try
+ {
+ if (obj is IConvertible)
+ {
+ value = (T)Convert.ChangeType(obj, typeof(T), FrameworkPortability.InvariantCulture);
+ }
+ else
+ {
+ value = (T) obj;
+ }
+ }
+ catch
+ {
+ _ready = _input.MoveNext();
+ return false;
+ }
+ }
+ _ready = _input.MoveNext();
+ return true;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Boolean from the input
+ /// </summary>
+ protected override bool Read(ref bool value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Int32 from the input
+ /// </summary>
+ protected override bool Read(ref int value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt32 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override bool Read(ref uint value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Int64 from the input
+ /// </summary>
+ protected override bool Read(ref long value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a UInt64 from the input
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override bool Read(ref ulong value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Single from the input
+ /// </summary>
+ protected override bool Read(ref float value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a Double from the input
+ /// </summary>
+ protected override bool Read(ref double value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected override bool Read(ref string value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a ByteString from the input
+ /// </summary>
+ protected override bool Read(ref ByteString value)
+ {
+ byte[] rawbytes = null;
+ if (GetValue(ref rawbytes))
+ {
+ value = ByteString.CopyFrom(rawbytes);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// returns true if it was able to read a single value into the value reference. The value
+ /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
+ /// </summary>
+ protected override bool ReadEnum(ref object value)
+ {
+ return GetValue(ref value);
+ }
+
+ /// <summary>
+ /// Merges the input stream into the provided IBuilderLite
+ /// </summary>
+ protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
+ {
+ IDictionary<string, object> values = null;
+ if (GetValue(ref values))
+ {
+ new DictionaryReader(values).Merge(builder, registry);
+ return true;
+ }
+ return false;
+ }
+
+ public override bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
+ {
+ object[] array = null;
+ if (GetValue(ref array))
+ {
+ if (typeof(T) == typeof(ByteString))
+ {
+ ICollection<ByteString> output = (ICollection<ByteString>) items;
+ foreach (byte[] item in array)
+ {
+ output.Add(ByteString.CopyFrom(item));
+ }
+ }
+ else
+ {
+ foreach (T item in array)
+ {
+ items.Add(item);
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public override bool ReadEnumArray(string field, ICollection<object> items)
+ {
+ object[] array = null;
+ if (GetValue(ref array))
+ {
+ foreach (object item in array)
+ {
+ items.Add(item);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public override bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
+ ExtensionRegistry registry)
+ {
+ object[] array = null;
+ if (GetValue(ref array))
+ {
+ foreach (IDictionary<string, object> item in array)
+ {
+ IBuilderLite builder = messageType.WeakCreateBuilderForType();
+ new DictionaryReader(item).Merge(builder);
+ items.Add((T) builder.WeakBuild());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public override bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
+ ExtensionRegistry registry)
+ {
+ return ReadMessageArray(field, items, messageType, registry);
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/DictionaryWriter.cs b/csharp/src/ProtocolBuffers.Serialization/DictionaryWriter.cs
new file mode 100644
index 00000000..6d823301
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/DictionaryWriter.cs
@@ -0,0 +1,202 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Google.ProtocolBuffers.Descriptors;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Allows writing messages to a name/value dictionary
+ /// </summary>
+ public class DictionaryWriter : AbstractWriter
+ {
+ private readonly IDictionary<string, object> _output;
+
+ /// <summary>
+ /// Constructs a writer using a new dictionary
+ /// </summary>
+ public DictionaryWriter()
+ : this(new Dictionary<string, object>(StringComparer.Ordinal))
+ {
+ }
+
+ /// <summary>
+ /// Constructs a writer using an existing dictionary
+ /// </summary>
+ public DictionaryWriter(IDictionary<string, object> output)
+ {
+ ThrowHelper.ThrowIfNull(output, "output");
+ _output = output;
+ }
+
+ /// <summary>
+ /// Creates the dictionary instance for a child message.
+ /// </summary>
+ protected virtual DictionaryWriter Create()
+ {
+ return new DictionaryWriter();
+ }
+
+ /// <summary>
+ /// Accesses the dictionary that is backing this writer
+ /// </summary>
+ public IDictionary<string, object> ToDictionary()
+ {
+ return _output;
+ }
+
+ /// <summary>
+ /// Writes the message to the the formatted stream.
+ /// </summary>
+ public override void WriteMessage(IMessageLite message)
+ {
+ message.WriteTo(this);
+ }
+
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void WriteMessageStart()
+ { }
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void WriteMessageEnd()
+ { }
+
+ /// <summary>
+ /// Writes a Boolean value
+ /// </summary>
+ protected override void Write(string field, bool value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a Int32 value
+ /// </summary>
+ protected override void Write(string field, int value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a UInt32 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override void Write(string field, uint value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a Int64 value
+ /// </summary>
+ protected override void Write(string field, long value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a UInt64 value
+ /// </summary>
+ [CLSCompliant(false)]
+ protected override void Write(string field, ulong value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a Single value
+ /// </summary>
+ protected override void Write(string field, float value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a Double value
+ /// </summary>
+ protected override void Write(string field, double value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a String value
+ /// </summary>
+ protected override void Write(string field, string value)
+ {
+ _output[field] = value;
+ }
+
+ /// <summary>
+ /// Writes a set of bytes
+ /// </summary>
+ protected override void Write(string field, ByteString value)
+ {
+ _output[field] = value.ToByteArray();
+ }
+
+ /// <summary>
+ /// Writes a message or group as a field
+ /// </summary>
+ protected override void WriteMessageOrGroup(string field, IMessageLite message)
+ {
+ DictionaryWriter writer = Create();
+ writer.WriteMessage(message);
+
+ _output[field] = writer.ToDictionary();
+ }
+
+ /// <summary>
+ /// Writes a System.Enum by the numeric and textual value
+ /// </summary>
+ protected override void WriteEnum(string field, int number, string name)
+ {
+ _output[field] = number;
+ }
+
+ /// <summary>
+ /// Writes an array of field values
+ /// </summary>
+ protected override void WriteArray(FieldType fieldType, string field, IEnumerable items)
+ {
+ List<object> objects = new List<object>();
+ foreach (object o in items)
+ {
+ switch (fieldType)
+ {
+ case FieldType.Group:
+ case FieldType.Message:
+ {
+ DictionaryWriter writer = Create();
+ writer.WriteMessage((IMessageLite) o);
+ objects.Add(writer.ToDictionary());
+ }
+ break;
+ case FieldType.Bytes:
+ objects.Add(((ByteString) o).ToByteArray());
+ break;
+ case FieldType.Enum:
+ if (o is IEnumLite)
+ {
+ objects.Add(((IEnumLite) o).Number);
+ }
+ else
+ {
+ objects.Add((int) o);
+ }
+ break;
+ default:
+ objects.Add(o);
+ break;
+ }
+ }
+
+ _output[field] = objects.ToArray();
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/Extensions.cs b/csharp/src/ProtocolBuffers.Serialization/Extensions.cs
new file mode 100644
index 00000000..8aef0a9e
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/Extensions.cs
@@ -0,0 +1,213 @@
+using System;
+using System.Text;
+using System.IO;
+using System.Xml;
+using Google.ProtocolBuffers.Serialization;
+using Google.ProtocolBuffers.Serialization.Http;
+
+namespace Google.ProtocolBuffers
+{
+ /// <summary>
+ /// Extension methods for using serializers on instances of IMessageLite/IBuilderLite
+ /// </summary>
+ public static class Extensions
+ {
+ #region IMessageLite Extension
+ /// <summary>
+ /// Serializes the message to JSON text. This is a trivial wrapper
+ /// around Serialization.JsonFormatWriter.WriteMessage.
+ /// </summary>
+ public static string ToJson(
+#if !NOEXTENSIONS
+ this
+#endif
+ IMessageLite message)
+ {
+ JsonFormatWriter w = JsonFormatWriter.CreateInstance();
+ w.WriteMessage(message);
+ return w.ToString();
+ }
+ /// <summary>
+ /// Serializes the message to XML text. This is a trivial wrapper
+ /// around Serialization.XmlFormatWriter.WriteMessage.
+ /// </summary>
+ public static string ToXml(
+#if !NOEXTENSIONS
+ this
+#endif
+ IMessageLite message)
+ {
+ StringWriter w = new StringWriter(new StringBuilder(4096));
+ XmlFormatWriter.CreateInstance(w).WriteMessage(message);
+ return w.ToString();
+ }
+ /// <summary>
+ /// Serializes the message to XML text using the element name provided.
+ /// This is a trivial wrapper around Serialization.XmlFormatWriter.WriteMessage.
+ /// </summary>
+ public static string ToXml(
+#if !NOEXTENSIONS
+ this
+#endif
+ IMessageLite message, string rootElementName)
+ {
+ StringWriter w = new StringWriter(new StringBuilder(4096));
+ XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, message);
+ return w.ToString();
+ }
+
+ /// <summary>
+ /// Writes the message instance to the stream using the content type provided
+ /// </summary>
+ /// <param name="message">An instance of a message</param>
+ /// <param name="options">Options specific to writing this message and/or content type</param>
+ /// <param name="contentType">The mime type of the content to be written</param>
+ /// <param name="output">The stream to write the message to</param>
+ public static void WriteTo(
+#if !NOEXTENSIONS
+ this
+#endif
+ IMessageLite message, MessageFormatOptions options, string contentType, Stream output)
+ {
+ ICodedOutputStream codedOutput = MessageFormatFactory.CreateOutputStream(options, contentType, output);
+
+ // Output the appropriate message preamble
+ codedOutput.WriteMessageStart();
+
+ // Write the message content to the output
+ message.WriteTo(codedOutput);
+
+ // Write the closing message fragment
+ codedOutput.WriteMessageEnd();
+ codedOutput.Flush();
+ }
+
+ #endregion
+ #region IBuilderLite Extensions
+ /// <summary>
+ /// Merges a JSON object into this builder and returns
+ /// </summary>
+ public static TBuilder MergeFromJson<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, string jsonText) where TBuilder : IBuilderLite
+ {
+ return JsonFormatReader.CreateInstance(jsonText)
+ .Merge(builder);
+ }
+ /// <summary>
+ /// Merges a JSON object into this builder and returns
+ /// </summary>
+ public static TBuilder MergeFromJson<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, TextReader reader) where TBuilder : IBuilderLite
+ {
+ return MergeFromJson(builder, reader, ExtensionRegistry.Empty);
+ }
+ /// <summary>
+ /// Merges a JSON object into this builder using the extensions provided and returns
+ /// </summary>
+ public static TBuilder MergeFromJson<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, TextReader reader, ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite
+ {
+ return JsonFormatReader.CreateInstance(reader)
+ .Merge(builder, extensionRegistry);
+ }
+
+ /// <summary>
+ /// Merges an XML object into this builder and returns
+ /// </summary>
+ public static TBuilder MergeFromXml<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, XmlReader reader) where TBuilder : IBuilderLite
+ {
+ return MergeFromXml(builder, XmlFormatReader.DefaultRootElementName, reader, ExtensionRegistry.Empty);
+ }
+
+ /// <summary>
+ /// Merges an XML object into this builder and returns
+ /// </summary>
+ public static TBuilder MergeFromXml<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, string rootElementName, XmlReader reader) where TBuilder : IBuilderLite
+ {
+ return MergeFromXml(builder, rootElementName, reader, ExtensionRegistry.Empty);
+ }
+
+ /// <summary>
+ /// Merges an XML object into this builder using the extensions provided and returns
+ /// </summary>
+ public static TBuilder MergeFromXml<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, string rootElementName, XmlReader reader,
+ ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite
+ {
+ return XmlFormatReader.CreateInstance(reader)
+ .Merge(rootElementName, builder, extensionRegistry);
+ }
+
+ /// <summary>
+ /// Merges the message from the input stream based on the contentType provided
+ /// </summary>
+ /// <typeparam name="TBuilder">A type derived from IBuilderLite</typeparam>
+ /// <param name="builder">An instance of a message builder</param>
+ /// <param name="options">Options specific to reading this message and/or content type</param>
+ /// <param name="contentType">The mime type of the input stream content</param>
+ /// <param name="input">The stream to read the message from</param>
+ /// <returns>The same builder instance that was supplied in the builder parameter</returns>
+ public static TBuilder MergeFrom<TBuilder>(
+#if !NOEXTENSIONS
+ this
+#endif
+ TBuilder builder, MessageFormatOptions options, string contentType, Stream input) where TBuilder : IBuilderLite
+ {
+ ICodedInputStream codedInput = MessageFormatFactory.CreateInputStream(options, contentType, input);
+ codedInput.ReadMessageStart();
+ builder.WeakMergeFrom(codedInput, options.ExtensionRegistry);
+ codedInput.ReadMessageEnd();
+ return builder;
+ }
+
+ #endregion
+ #region IRpcServerStub Extensions
+
+ /// <summary>
+ /// Used to implement a service endpoint on an HTTP server. This works with services generated with the
+ /// service_generator_type option set to IRPCDISPATCH.
+ /// </summary>
+ /// <param name="stub">The service execution stub</param>
+ /// <param name="methodName">The name of the method being invoked</param>
+ /// <param name="options">optional arguments for the format reader/writer</param>
+ /// <param name="contentType">The mime type for the input stream</param>
+ /// <param name="input">The input stream</param>
+ /// <param name="responseType">The mime type for the output stream</param>
+ /// <param name="output">The output stream</param>
+ public static void HttpCallMethod(
+#if !NOEXTENSIONS
+ this
+#endif
+ IRpcServerStub stub, string methodName, MessageFormatOptions options,
+ string contentType, Stream input, string responseType, Stream output)
+ {
+ ICodedInputStream codedInput = MessageFormatFactory.CreateInputStream(options, contentType, input);
+ codedInput.ReadMessageStart();
+ IMessageLite response = stub.CallMethod(methodName, codedInput, options.ExtensionRegistry);
+ codedInput.ReadMessageEnd();
+ WriteTo(response, options, responseType, output);
+ }
+
+ #endregion
+ }
+}
diff --git a/csharp/src/ProtocolBuffers.Serialization/Http/FormUrlEncodedReader.cs b/csharp/src/ProtocolBuffers.Serialization/Http/FormUrlEncodedReader.cs
new file mode 100644
index 00000000..508d76a9
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/Http/FormUrlEncodedReader.cs
@@ -0,0 +1,162 @@
+using System;
+using System.IO;
+using System.Text;
+
+namespace Google.ProtocolBuffers.Serialization.Http
+{
+ /// <summary>
+ /// Allows reading messages from a name/value dictionary
+ /// </summary>
+ public class FormUrlEncodedReader : AbstractTextReader
+ {
+ private readonly TextReader _input;
+ private string _fieldName, _fieldValue;
+ private bool _ready;
+
+ /// <summary>
+ /// Creates a dictionary reader from an enumeration of KeyValuePair data, like an IDictionary
+ /// </summary>
+ FormUrlEncodedReader(TextReader input)
+ {
+ _input = input;
+ int ch = input.Peek();
+ if (ch == '?')
+ {
+ input.Read();
+ }
+ _ready = ReadNext();
+ }
+
+ #region CreateInstance overloads
+ /// <summary>
+ /// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
+ /// </summary>
+ public static FormUrlEncodedReader CreateInstance(Stream stream)
+ {
+ return new FormUrlEncodedReader(new StreamReader(stream, Encoding.UTF8, false));
+ }
+
+ /// <summary>
+ /// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
+ /// </summary>
+ public static FormUrlEncodedReader CreateInstance(byte[] bytes)
+ {
+ return new FormUrlEncodedReader(new StreamReader(new MemoryStream(bytes, false), Encoding.UTF8, false));
+ }
+
+ /// <summary>
+ /// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
+ /// </summary>
+ public static FormUrlEncodedReader CreateInstance(string text)
+ {
+ return new FormUrlEncodedReader(new StringReader(text));
+ }
+
+ /// <summary>
+ /// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
+ /// </summary>
+ public static FormUrlEncodedReader CreateInstance(TextReader input)
+ {
+ return new FormUrlEncodedReader(input);
+ }
+ #endregion
+
+ private bool ReadNext()
+ {
+ StringBuilder field = new StringBuilder(32);
+ StringBuilder value = new StringBuilder(64);
+ int ch;
+ while (-1 != (ch = _input.Read()) && ch != '=' && ch != '&')
+ {
+ field.Append((char)ch);
+ }
+
+ if (ch != -1 && ch != '&')
+ {
+ while (-1 != (ch = _input.Read()) && ch != '&')
+ {
+ value.Append((char)ch);
+ }
+ }
+
+ _fieldName = field.ToString();
+ _fieldValue = Uri.UnescapeDataString(value.Replace('+', ' ').ToString());
+
+ return !String.IsNullOrEmpty(_fieldName);
+ }
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void ReadMessageStart()
+ { }
+
+ /// <summary>
+ /// No-op
+ /// </summary>
+ public override void ReadMessageEnd()
+ { }
+
+ /// <summary>
+ /// Merges the contents of stream into the provided message builder
+ /// </summary>
+ public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
+ {
+ builder.WeakMergeFrom(this, registry);
+ return builder;
+ }
+
+ /// <summary>
+ /// Causes the reader to skip past this field
+ /// </summary>
+ protected override void Skip()
+ {
+ _ready = ReadNext();
+ }
+
+ /// <summary>
+ /// Peeks at the next field in the input stream and returns what information is available.
+ /// </summary>
+ /// <remarks>
+ /// This may be called multiple times without actually reading the field. Only after the field
+ /// is either read, or skipped, should PeekNext return a different value.
+ /// </remarks>
+ protected override bool PeekNext(out string field)
+ {
+ field = _ready ? _fieldName : null;
+ return field != null;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected override bool ReadAsText(ref string value, Type typeInfo)
+ {
+ if (_ready)
+ {
+ value = _fieldValue;
+ _ready = ReadNext();
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// It's unlikely this will work for anything but text data as bytes UTF8 are transformed to text and back to bytes
+ /// </summary>
+ protected override ByteString DecodeBytes(string bytes)
+ { return ByteString.CopyFromUtf8(bytes); }
+
+ /// <summary>
+ /// Not Supported
+ /// </summary>
+ public override bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
+ { throw new NotSupportedException(); }
+
+ /// <summary>
+ /// Not Supported
+ /// </summary>
+ protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
+ { throw new NotSupportedException(); }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs b/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs
new file mode 100644
index 00000000..270af64b
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs
@@ -0,0 +1,112 @@
+using System;
+using System.IO;
+using System.Xml;
+using System.Text;
+
+namespace Google.ProtocolBuffers.Serialization.Http
+{
+ /// <summary>
+ /// Extensions and helpers to abstract the reading/writing of messages by a client-specified content type.
+ /// </summary>
+ public static class MessageFormatFactory
+ {
+ /// <summary>
+ /// Constructs an ICodedInputStream from the input stream based on the contentType provided
+ /// </summary>
+ /// <param name="options">Options specific to reading this message and/or content type</param>
+ /// <param name="contentType">The mime type of the input stream content</param>
+ /// <param name="input">The stream to read the message from</param>
+ /// <returns>The ICodedInputStream that can be given to the IBuilder.MergeFrom(...) method</returns>
+ public static ICodedInputStream CreateInputStream(MessageFormatOptions options, string contentType, Stream input)
+ {
+ ICodedInputStream codedInput = ContentTypeToInputStream(contentType, options, input);
+
+ if (codedInput is XmlFormatReader)
+ {
+ XmlFormatReader reader = (XmlFormatReader)codedInput;
+ reader.RootElementName = options.XmlReaderRootElementName;
+ reader.Options = options.XmlReaderOptions;
+ }
+
+ return codedInput;
+ }
+
+ /// <summary>
+ /// Writes the message instance to the stream using the content type provided
+ /// </summary>
+ /// <param name="options">Options specific to writing this message and/or content type</param>
+ /// <param name="contentType">The mime type of the content to be written</param>
+ /// <param name="output">The stream to write the message to</param>
+ /// <remarks> If you do not dispose of ICodedOutputStream some formats may yield incomplete output </remarks>
+ public static ICodedOutputStream CreateOutputStream(MessageFormatOptions options, string contentType, Stream output)
+ {
+ ICodedOutputStream codedOutput = ContentTypeToOutputStream(contentType, options, output);
+
+ if (codedOutput is JsonFormatWriter)
+ {
+ JsonFormatWriter writer = (JsonFormatWriter)codedOutput;
+ if (options.FormattedOutput)
+ {
+ writer.Formatted();
+ }
+ }
+ else if (codedOutput is XmlFormatWriter)
+ {
+ XmlFormatWriter writer = (XmlFormatWriter)codedOutput;
+ if (options.FormattedOutput)
+ {
+ XmlWriterSettings settings = new XmlWriterSettings()
+ {
+ CheckCharacters = false,
+ NewLineHandling = NewLineHandling.Entitize,
+ OmitXmlDeclaration = true,
+ Encoding = new UTF8Encoding(false),
+ Indent = true,
+ IndentChars = " ",
+ };
+ // Don't know how else to change xml writer options?
+ codedOutput = writer = XmlFormatWriter.CreateInstance(XmlWriter.Create(output, settings));
+ }
+ writer.RootElementName = options.XmlWriterRootElementName;
+ writer.Options = options.XmlWriterOptions;
+ }
+
+ return codedOutput;
+ }
+
+ private static ICodedInputStream ContentTypeToInputStream(string contentType, MessageFormatOptions options, Stream input)
+ {
+ contentType = (contentType ?? String.Empty).Split(';')[0].Trim();
+
+ CodedInputBuilder factory;
+ if(!options.MimeInputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null)
+ {
+ if(String.IsNullOrEmpty(options.DefaultContentType) ||
+ !options.MimeInputTypesReadOnly.TryGetValue(options.DefaultContentType, out factory) || factory == null)
+ {
+ throw new ArgumentOutOfRangeException("contentType");
+ }
+ }
+
+ return factory(input);
+ }
+
+ private static ICodedOutputStream ContentTypeToOutputStream(string contentType, MessageFormatOptions options, Stream output)
+ {
+ contentType = (contentType ?? String.Empty).Split(';')[0].Trim();
+
+ CodedOutputBuilder factory;
+ if (!options.MimeOutputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null)
+ {
+ if (String.IsNullOrEmpty(options.DefaultContentType) ||
+ !options.MimeOutputTypesReadOnly.TryGetValue(options.DefaultContentType, out factory) || factory == null)
+ {
+ throw new ArgumentOutOfRangeException("contentType");
+ }
+ }
+
+ return factory(output);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs b/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs
new file mode 100644
index 00000000..1480e50a
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs
@@ -0,0 +1,176 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using Google.ProtocolBuffers.Collections;
+
+namespace Google.ProtocolBuffers.Serialization.Http
+{
+ /// <summary>
+ /// A delegate used to specify a method that constructs an ICodedInputStream from a .NET Stream.
+ /// </summary>
+ public delegate ICodedInputStream CodedInputBuilder(Stream stream);
+ /// <summary>
+ /// A delegate used to specify a method that constructs an ICodedOutputStream from a .NET Stream.
+ /// </summary>
+ public delegate ICodedOutputStream CodedOutputBuilder(Stream stream);
+
+ /// <summary>
+ /// Defines control information for the various formatting used with HTTP services
+ /// </summary>
+ public class MessageFormatOptions
+ {
+ /// <summary>The mime type for xml content</summary>
+ /// <remarks>Other valid xml mime types include: application/binary, application/x-protobuf</remarks>
+ public const string ContentTypeProtoBuffer = "application/vnd.google.protobuf";
+
+ /// <summary>The mime type for xml content</summary>
+ /// <remarks>Other valid xml mime types include: text/xml</remarks>
+ public const string ContentTypeXml = "application/xml";
+
+ /// <summary>The mime type for json content</summary>
+ /// <remarks>
+ /// Other valid json mime types include: application/json, application/x-json,
+ /// application/x-javascript, text/javascript, text/x-javascript, text/x-json, text/json
+ /// </remarks>
+ public const string ContentTypeJson = "application/json";
+
+ /// <summary>The mime type for query strings and x-www-form-urlencoded content</summary>
+ /// <remarks>This mime type is input-only</remarks>
+ public const string ContentFormUrlEncoded = "application/x-www-form-urlencoded";
+
+ /// <summary>
+ /// Default mime-type handling for input
+ /// </summary>
+ private static readonly IDictionary<string, CodedInputBuilder> MimeInputDefaults =
+ new ReadOnlyDictionary<string, CodedInputBuilder>(
+ new Dictionary<string, CodedInputBuilder>(StringComparer.OrdinalIgnoreCase)
+ {
+ {"application/json", JsonFormatReader.CreateInstance},
+ {"application/x-json", JsonFormatReader.CreateInstance},
+ {"application/x-javascript", JsonFormatReader.CreateInstance},
+ {"text/javascript", JsonFormatReader.CreateInstance},
+ {"text/x-javascript", JsonFormatReader.CreateInstance},
+ {"text/x-json", JsonFormatReader.CreateInstance},
+ {"text/json", JsonFormatReader.CreateInstance},
+ {"text/xml", XmlFormatReader.CreateInstance},
+ {"application/xml", XmlFormatReader.CreateInstance},
+ {"application/binary", CodedInputStream.CreateInstance},
+ {"application/x-protobuf", CodedInputStream.CreateInstance},
+ {"application/vnd.google.protobuf", CodedInputStream.CreateInstance},
+ {"application/x-www-form-urlencoded", FormUrlEncodedReader.CreateInstance},
+ }
+ );
+
+ /// <summary>
+ /// Default mime-type handling for output
+ /// </summary>
+ private static readonly IDictionary<string, CodedOutputBuilder> MimeOutputDefaults =
+ new ReadOnlyDictionary<string, CodedOutputBuilder>(
+ new Dictionary<string, CodedOutputBuilder>(StringComparer.OrdinalIgnoreCase)
+ {
+ {"application/json", JsonFormatWriter.CreateInstance},
+ {"application/x-json", JsonFormatWriter.CreateInstance},
+ {"application/x-javascript", JsonFormatWriter.CreateInstance},
+ {"text/javascript", JsonFormatWriter.CreateInstance},
+ {"text/x-javascript", JsonFormatWriter.CreateInstance},
+ {"text/x-json", JsonFormatWriter.CreateInstance},
+ {"text/json", JsonFormatWriter.CreateInstance},
+ {"text/xml", XmlFormatWriter.CreateInstance},
+ {"application/xml", XmlFormatWriter.CreateInstance},
+ {"application/binary", CodedOutputStream.CreateInstance},
+ {"application/x-protobuf", CodedOutputStream.CreateInstance},
+ {"application/vnd.google.protobuf", CodedOutputStream.CreateInstance},
+ }
+ );
+
+
+
+
+ private string _defaultContentType;
+ private string _xmlReaderRootElementName;
+ private string _xmlWriterRootElementName;
+ private ExtensionRegistry _extensionRegistry;
+ private Dictionary<string, CodedInputBuilder> _mimeInputTypes;
+ private Dictionary<string, CodedOutputBuilder> _mimeOutputTypes;
+
+ /// <summary> Provides access to modify the mime-type input stream construction </summary>
+ public IDictionary<string, CodedInputBuilder> MimeInputTypes
+ {
+ get
+ {
+ return _mimeInputTypes ??
+ (_mimeInputTypes = new Dictionary<string, CodedInputBuilder>(
+ MimeInputDefaults, StringComparer.OrdinalIgnoreCase));
+ }
+ }
+
+ /// <summary> Provides access to modify the mime-type input stream construction </summary>
+ public IDictionary<string, CodedOutputBuilder> MimeOutputTypes
+ {
+ get
+ {
+ return _mimeOutputTypes ??
+ (_mimeOutputTypes = new Dictionary<string, CodedOutputBuilder>(
+ MimeOutputDefaults, StringComparer.OrdinalIgnoreCase));
+ }
+ }
+
+ internal IDictionary<string, CodedInputBuilder> MimeInputTypesReadOnly
+ { get { return _mimeInputTypes ?? MimeInputDefaults; } }
+
+ internal IDictionary<string, CodedOutputBuilder> MimeOutputTypesReadOnly
+ { get { return _mimeOutputTypes ?? MimeOutputDefaults; } }
+
+ /// <summary>
+ /// The default content type to use if the input type is null or empty. If this
+ /// value is not supplied an ArgumentOutOfRangeException exception will be raised.
+ /// </summary>
+ public string DefaultContentType
+ {
+ get { return _defaultContentType ?? String.Empty; }
+ set { _defaultContentType = value; }
+ }
+
+ /// <summary>
+ /// The extension registry to use when reading messages
+ /// </summary>
+ public ExtensionRegistry ExtensionRegistry
+ {
+ get { return _extensionRegistry ?? ExtensionRegistry.Empty; }
+ set { _extensionRegistry = value; }
+ }
+
+ /// <summary>
+ /// The name of the xml root element when reading messages
+ /// </summary>
+ public string XmlReaderRootElementName
+ {
+ get { return _xmlReaderRootElementName ?? XmlFormatReader.DefaultRootElementName; }
+ set { _xmlReaderRootElementName = value; }
+ }
+
+ /// <summary>
+ /// Xml reader options
+ /// </summary>
+ public XmlReaderOptions XmlReaderOptions { get; set; }
+
+ /// <summary>
+ /// True to use formatted output including new-lines and default indentation
+ /// </summary>
+ public bool FormattedOutput { get; set; }
+
+ /// <summary>
+ /// The name of the xml root element when writing messages
+ /// </summary>
+ public string XmlWriterRootElementName
+ {
+ get { return _xmlWriterRootElementName ?? XmlFormatWriter.DefaultRootElementName; }
+ set { _xmlWriterRootElementName = value; }
+ }
+
+ /// <summary>
+ /// Xml writer options
+ /// </summary>
+ public XmlWriterOptions XmlWriterOptions { get; set; }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/JsonFormatReader.cs b/csharp/src/ProtocolBuffers.Serialization/JsonFormatReader.cs
new file mode 100644
index 00000000..423196d8
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/JsonFormatReader.cs
@@ -0,0 +1,262 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// JsonFormatReader is used to parse Json into a message or an array of messages
+ /// </summary>
+ public class JsonFormatReader : AbstractTextReader
+ {
+ private readonly JsonCursor _input;
+ // The expected token that ends the current item, either ']' or '}'
+ private readonly Stack<int> _stopChar;
+
+ private enum ReaderState
+ {
+ Start,
+ BeginValue,
+ EndValue,
+ BeginObject,
+ BeginArray
+ }
+
+ private string _current;
+ private ReaderState _state;
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message, this method does not use text encoding, all bytes MUST
+ /// represent ASCII character values.
+ /// </summary>
+ public static JsonFormatReader CreateInstance(Stream stream)
+ {
+ return new JsonFormatReader(JsonCursor.CreateInstance(stream));
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message, this method does not use text encoding, all bytes MUST
+ /// represent ASCII character values.
+ /// </summary>
+ public static JsonFormatReader CreateInstance(byte[] bytes)
+ {
+ return new JsonFormatReader(JsonCursor.CreateInstance(bytes));
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message
+ /// </summary>
+ public static JsonFormatReader CreateInstance(string jsonText)
+ {
+ return new JsonFormatReader(JsonCursor.CreateInstance(jsonText));
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message
+ /// </summary>
+ public static JsonFormatReader CreateInstance(TextReader input)
+ {
+ return new JsonFormatReader(JsonCursor.CreateInstance(input));
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message
+ /// </summary>
+ internal JsonFormatReader(JsonCursor input)
+ {
+ _input = input;
+ _stopChar = new Stack<int>();
+ _stopChar.Push(-1);
+ _state = ReaderState.Start;
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatReader to parse Json into a message
+ /// </summary>
+ protected JsonFormatReader(TextReader input)
+ : this(JsonCursor.CreateInstance(input))
+ {
+ }
+
+ /// <summary>
+ /// Returns true if the reader is currently on an array element
+ /// </summary>
+ public bool IsArrayMessage
+ {
+ get { return _input.NextChar == '['; }
+ }
+
+ /// <summary>
+ /// Returns an enumerator that is used to cursor over an array of messages
+ /// </summary>
+ /// <remarks>
+ /// This is generally used when receiving an array of messages rather than a single root message
+ /// </remarks>
+ public IEnumerable<JsonFormatReader> EnumerateArray()
+ {
+ foreach (string ignored in ForeachArrayItem(_current))
+ {
+ yield return this;
+ }
+ }
+
+ /// <summary>
+ /// Reads the root-message preamble specific to this formatter
+ /// </summary>
+ public override void ReadMessageStart()
+ {
+ _input.Consume('{');
+ _stopChar.Push('}');
+
+ _state = ReaderState.BeginObject;
+ }
+
+ /// <summary>
+ /// Reads the root-message close specific to this formatter
+ /// </summary>
+ public override void ReadMessageEnd()
+ {
+ _input.Consume((char)_stopChar.Pop());
+ _state = ReaderState.EndValue;
+ }
+
+ /// <summary>
+ /// Merges the contents of stream into the provided message builder
+ /// </summary>
+ public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
+ {
+ ReadMessageStart();
+ builder.WeakMergeFrom(this, registry);
+ ReadMessageEnd();
+ return builder;
+ }
+
+ /// <summary>
+ /// Causes the reader to skip past this field
+ /// </summary>
+ protected override void Skip()
+ {
+ object temp;
+ _input.ReadVariant(out temp);
+ _state = ReaderState.EndValue;
+ }
+
+ /// <summary>
+ /// Peeks at the next field in the input stream and returns what information is available.
+ /// </summary>
+ /// <remarks>
+ /// This may be called multiple times without actually reading the field. Only after the field
+ /// is either read, or skipped, should PeekNext return a different value.
+ /// </remarks>
+ protected override bool PeekNext(out string field)
+ {
+ field = _current;
+ if (_state == ReaderState.BeginValue)
+ {
+ return true;
+ }
+
+ int next = _input.NextChar;
+ if (next == _stopChar.Peek())
+ {
+ return false;
+ }
+
+ _input.Assert(next != -1, "Unexpected end of file.");
+
+ //not sure about this yet, it will allow {, "a":true }
+ if (_state == ReaderState.EndValue && !_input.TryConsume(','))
+ {
+ return false;
+ }
+
+ field = _current = _input.ReadString();
+ _input.Consume(':');
+ _state = ReaderState.BeginValue;
+ return true;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected override bool ReadAsText(ref string value, Type typeInfo)
+ {
+ object temp;
+ JsonCursor.JsType type = _input.ReadVariant(out temp);
+ _state = ReaderState.EndValue;
+
+ _input.Assert(type != JsonCursor.JsType.Array && type != JsonCursor.JsType.Object,
+ "Encountered {0} while expecting {1}", type, typeInfo);
+ if (type == JsonCursor.JsType.Null)
+ {
+ return false;
+ }
+ if (type == JsonCursor.JsType.True)
+ {
+ value = "1";
+ }
+ else if (type == JsonCursor.JsType.False)
+ {
+ value = "0";
+ }
+ else
+ {
+ value = temp as string;
+ }
+
+ //exponent representation of integer number:
+ if (value != null && type == JsonCursor.JsType.Number &&
+ (typeInfo != typeof(double) && typeInfo != typeof(float)) &&
+ value.IndexOf("e", StringComparison.OrdinalIgnoreCase) > 0)
+ {
+ value = XmlConvert.ToString((long) Math.Round(XmlConvert.ToDouble(value), 0));
+ }
+ return value != null;
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a ByteString from the input
+ /// </summary>
+ protected override bool Read(ref ByteString value)
+ {
+ string bytes = null;
+ if (Read(ref bytes))
+ {
+ value = ByteString.FromBase64(bytes);
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Cursors through the array elements and stops at the end of the array
+ /// </summary>
+ protected override IEnumerable<string> ForeachArrayItem(string field)
+ {
+ _input.Consume('[');
+ _stopChar.Push(']');
+ _state = ReaderState.BeginArray;
+ while (_input.NextChar != ']')
+ {
+ _current = field;
+ yield return field;
+ if (!_input.TryConsume(','))
+ {
+ break;
+ }
+ }
+ _input.Consume((char) _stopChar.Pop());
+ _state = ReaderState.EndValue;
+ }
+
+ /// <summary>
+ /// Merges the input stream into the provided IBuilderLite
+ /// </summary>
+ protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
+ {
+ Merge(builder, registry);
+ return true;
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs b/csharp/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
new file mode 100644
index 00000000..15e0424e
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
@@ -0,0 +1,541 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using Google.ProtocolBuffers.Descriptors;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// JsonFormatWriter is a .NET 2.0 friendly json formatter for proto buffer messages. For .NET 3.5
+ /// you may also use the XmlFormatWriter with an XmlWriter created by the
+ /// <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory">JsonReaderWriterFactory</see>.
+ /// </summary>
+ public abstract class JsonFormatWriter : AbstractTextWriter
+ {
+ #region buffering implementations
+
+ private class JsonTextWriter : JsonFormatWriter
+ {
+ private readonly char[] _buffer;
+ private TextWriter _output;
+ private int _bufferPos;
+
+ public JsonTextWriter(TextWriter output)
+ {
+ _buffer = new char[4096];
+ _bufferPos = 0;
+ _output = output;
+ _counter.Add(0);
+ }
+
+ /// <summary>
+ /// Returns the output of TextWriter.ToString() where TextWriter is the ctor argument.
+ /// </summary>
+ public override string ToString()
+ {
+ Flush();
+
+ if (_output != null)
+ {
+ return _output.ToString();
+ }
+
+ return new String(_buffer, 0, _bufferPos);
+ }
+
+ protected override void WriteToOutput(char[] chars, int offset, int len)
+ {
+ if (_bufferPos + len >= _buffer.Length)
+ {
+ if (_output == null)
+ {
+ _output = new StringWriter(new StringBuilder(_buffer.Length*2 + len));
+ }
+ Flush();
+ }
+
+ if (len < _buffer.Length)
+ {
+ if (len <= 12)
+ {
+ int stop = offset + len;
+ for (int i = offset; i < stop; i++)
+ {
+ _buffer[_bufferPos++] = chars[i];
+ }
+ }
+ else
+ {
+ Buffer.BlockCopy(chars, offset << 1, _buffer, _bufferPos << 1, len << 1);
+ _bufferPos += len;
+ }
+ }
+ else
+ {
+ _output.Write(chars, offset, len);
+ }
+ }
+
+ protected override void WriteToOutput(char ch)
+ {
+ if (_bufferPos >= _buffer.Length)
+ {
+ if (_output == null)
+ {
+ _output = new StringWriter(new StringBuilder(_buffer.Length * 2));
+ }
+ Flush();
+ }
+ _buffer[_bufferPos++] = ch;
+ }
+
+ public override void Flush()
+ {
+ if (_bufferPos > 0 && _output != null)
+ {
+ _output.Write(_buffer, 0, _bufferPos);
+ _bufferPos = 0;
+ }
+ base.Flush();
+ }
+ }
+
+ private class JsonStreamWriter : JsonFormatWriter
+ {
+ static readonly Encoding Encoding = new UTF8Encoding(false);
+ private readonly byte[] _buffer;
+ private Stream _output;
+ private int _bufferPos;
+
+ public JsonStreamWriter(Stream output)
+ {
+ _buffer = new byte[8192];
+ _bufferPos = 0;
+ _output = output;
+ _counter.Add(0);
+ }
+
+ protected override void WriteToOutput(char[] chars, int offset, int len)
+ {
+ if (_bufferPos + len >= _buffer.Length)
+ {
+ Flush();
+ }
+
+ if (len < _buffer.Length)
+ {
+ if (len <= 12)
+ {
+ int stop = offset + len;
+ for (int i = offset; i < stop; i++)
+ {
+ _buffer[_bufferPos++] = (byte) chars[i];
+ }
+ }
+ else
+ {
+ _bufferPos += Encoding.GetBytes(chars, offset, len, _buffer, _bufferPos);
+ }
+ }
+ else
+ {
+ byte[] temp = Encoding.GetBytes(chars, offset, len);
+ _output.Write(temp, 0, temp.Length);
+ }
+ }
+
+ protected override void WriteToOutput(char ch)
+ {
+ if (_bufferPos >= _buffer.Length)
+ {
+ Flush();
+ }
+ _buffer[_bufferPos++] = (byte) ch;
+ }
+
+ public override void Flush()
+ {
+ if (_bufferPos > 0 && _output != null)
+ {
+ _output.Write(_buffer, 0, _bufferPos);
+ _bufferPos = 0;
+ }
+ base.Flush();
+ }
+ }
+
+ #endregion
+
+ //Tracks the writer depth and the array element count at that depth.
+ private readonly List<int> _counter;
+ //True if the top-level of the writer is an array as opposed to a single message.
+ private bool _isArray;
+
+ /// <summary>
+ /// Constructs a JsonFormatWriter, use the ToString() member to extract the final Json on completion.
+ /// </summary>
+ protected JsonFormatWriter()
+ {
+ _counter = new List<int>();
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatWriter, use ToString() to extract the final output
+ /// </summary>
+ public static JsonFormatWriter CreateInstance()
+ {
+ return new JsonTextWriter(null);
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatWriter to output to the given text writer
+ /// </summary>
+ public static JsonFormatWriter CreateInstance(TextWriter output)
+ {
+ return new JsonTextWriter(output);
+ }
+
+ /// <summary>
+ /// Constructs a JsonFormatWriter to output to the given stream
+ /// </summary>
+ public static JsonFormatWriter CreateInstance(Stream output)
+ {
+ return new JsonStreamWriter(output);
+ }
+
+ /// <summary> Write to the output stream </summary>
+ protected void WriteToOutput(string format, params object[] args)
+ {
+ WriteToOutput(String.Format(format, args));
+ }
+
+ /// <summary> Write to the output stream </summary>
+ protected void WriteToOutput(string text)
+ {
+ WriteToOutput(text.ToCharArray(), 0, text.Length);
+ }
+
+ /// <summary> Write to the output stream </summary>
+ protected abstract void WriteToOutput(char ch);
+
+ /// <summary> Write to the output stream </summary>
+ protected abstract void WriteToOutput(char[] chars, int offset, int len);
+
+ /// <summary> Sets the output formatting to use Environment.NewLine with 4-character indentions </summary>
+ public JsonFormatWriter Formatted()
+ {
+ NewLine = FrameworkPortability.NewLine;
+ Indent = " ";
+ Whitespace = " ";
+ return this;
+ }
+
+ /// <summary> Gets or sets the characters to use for the new-line, default = empty </summary>
+ public string NewLine { get; set; }
+
+ /// <summary> Gets or sets the text to use for indenting, default = empty </summary>
+ public string Indent { get; set; }
+
+ /// <summary> Gets or sets the whitespace to use to separate the text, default = empty </summary>
+ public string Whitespace { get; set; }
+
+ private void Seperator()
+ {
+ if (_counter.Count == 0)
+ {
+ throw new InvalidOperationException("Mismatched open/close in Json writer.");
+ }
+
+ int index = _counter.Count - 1;
+ if (_counter[index] > 0)
+ {
+ WriteToOutput(',');
+ }
+
+ WriteLine(String.Empty);
+ _counter[index] = _counter[index] + 1;
+ }
+
+ private void WriteLine(string content)
+ {
+ if (!String.IsNullOrEmpty(NewLine))
+ {
+ WriteToOutput(NewLine);
+ for (int i = 1; i < _counter.Count; i++)
+ {
+ WriteToOutput(Indent);
+ }
+ }
+ else if (!String.IsNullOrEmpty(Whitespace))
+ {
+ WriteToOutput(Whitespace);
+ }
+
+ WriteToOutput(content);
+ }
+
+ private void WriteName(string field)
+ {
+ Seperator();
+ if (!String.IsNullOrEmpty(field))
+ {
+ WriteToOutput('"');
+ WriteToOutput(field);
+ WriteToOutput('"');
+ WriteToOutput(':');
+ if (!String.IsNullOrEmpty(Whitespace))
+ {
+ WriteToOutput(Whitespace);
+ }
+ }
+ }
+
+ private void EncodeText(string value)
+ {
+ char[] text = value.ToCharArray();
+ int len = text.Length;
+ int pos = 0;
+
+ while (pos < len)
+ {
+ int next = pos;
+ while (next < len && text[next] >= 32 && text[next] < 127 && text[next] != '\\' && text[next] != '/' &&
+ text[next] != '"')
+ {
+ next++;
+ }
+ WriteToOutput(text, pos, next - pos);
+ if (next < len)
+ {
+ switch (text[next])
+ {
+ case '"':
+ WriteToOutput(@"\""");
+ break;
+ case '\\':
+ WriteToOutput(@"\\");
+ break;
+ //odd at best to escape '/', most Json implementations don't, but it is defined in the rfc-4627
+ case '/':
+ WriteToOutput(@"\/");
+ break;
+ case '\b':
+ WriteToOutput(@"\b");
+ break;
+ case '\f':
+ WriteToOutput(@"\f");
+ break;
+ case '\n':
+ WriteToOutput(@"\n");
+ break;
+ case '\r':
+ WriteToOutput(@"\r");
+ break;
+ case '\t':
+ WriteToOutput(@"\t");
+ break;
+ default:
+ WriteToOutput(@"\u{0:x4}", (int) text[next]);
+ break;
+ }
+ next++;
+ }
+ pos = next;
+ }
+ }
+
+ /// <summary>
+ /// Writes a String value
+ /// </summary>
+ protected override void WriteAsText(string field, string textValue, object typedValue)
+ {
+ WriteName(field);
+ if (typedValue is bool || typedValue is int || typedValue is uint || typedValue is long ||
+ typedValue is ulong || typedValue is double || typedValue is float)
+ {
+ WriteToOutput(textValue);
+ }
+ else
+ {
+ WriteToOutput('"');
+ if (typedValue is string)
+ {
+ EncodeText(textValue);
+ }
+ else
+ {
+ WriteToOutput(textValue);
+ }
+ WriteToOutput('"');
+ }
+ }
+
+ /// <summary>
+ /// Writes a Double value
+ /// </summary>
+ protected override void Write(string field, double value)
+ {
+ if (double.IsNaN(value) || double.IsNegativeInfinity(value) || double.IsPositiveInfinity(value))
+ {
+ throw new InvalidOperationException("This format does not support NaN, Infinity, or -Infinity");
+ }
+ base.Write(field, value);
+ }
+
+ /// <summary>
+ /// Writes a Single value
+ /// </summary>
+ protected override void Write(string field, float value)
+ {
+ if (float.IsNaN(value) || float.IsNegativeInfinity(value) || float.IsPositiveInfinity(value))
+ {
+ throw new InvalidOperationException("This format does not support NaN, Infinity, or -Infinity");
+ }
+ base.Write(field, value);
+ }
+
+ // Treat enum as string
+ protected override void WriteEnum(string field, int number, string name)
+ {
+ Write(field, name);
+ }
+
+ /// <summary>
+ /// Writes an array of field values
+ /// </summary>
+ protected override void WriteArray(FieldType type, string field, IEnumerable items)
+ {
+ IEnumerator enumerator = items.GetEnumerator();
+ try
+ {
+ if (!enumerator.MoveNext())
+ {
+ return;
+ }
+ }
+ finally
+ {
+ if (enumerator is IDisposable)
+ {
+ ((IDisposable) enumerator).Dispose();
+ }
+ }
+
+ WriteName(field);
+ WriteToOutput("[");
+ _counter.Add(0);
+
+ base.WriteArray(type, String.Empty, items);
+
+ _counter.RemoveAt(_counter.Count - 1);
+ WriteLine("]");
+ }
+
+ /// <summary>
+ /// Writes a message
+ /// </summary>
+ protected override void WriteMessageOrGroup(string field, IMessageLite message)
+ {
+ WriteName(field);
+ WriteMessage(message);
+ }
+
+ /// <summary>
+ /// Writes the message to the the formatted stream.
+ /// </summary>
+ public override void WriteMessage(IMessageLite message)
+ {
+ WriteMessageStart();
+ message.WriteTo(this);
+ WriteMessageEnd();
+ }
+
+ /// <summary>
+ /// Used to write the root-message preamble, in json this is the left-curly brace '{'.
+ /// After this call you can call IMessageLite.MergeTo(...) and complete the message with
+ /// a call to WriteMessageEnd().
+ /// </summary>
+ public override void WriteMessageStart()
+ {
+ if (_isArray)
+ {
+ Seperator();
+ }
+ WriteToOutput("{");
+ _counter.Add(0);
+ }
+
+ /// <summary>
+ /// Used to complete a root-message previously started with a call to WriteMessageStart()
+ /// </summary>
+ public override void WriteMessageEnd()
+ {
+ _counter.RemoveAt(_counter.Count - 1);
+ WriteLine("}");
+ Flush();
+ }
+
+ /// <summary>
+ /// Used in streaming arrays of objects to the writer
+ /// </summary>
+ /// <example>
+ /// <code>
+ /// using(writer.StartArray())
+ /// foreach(IMessageLite m in messages)
+ /// writer.WriteMessage(m);
+ /// </code>
+ /// </example>
+ public sealed class JsonArray : IDisposable
+ {
+ private JsonFormatWriter _writer;
+
+ internal JsonArray(JsonFormatWriter writer)
+ {
+ _writer = writer;
+ _writer.WriteToOutput("[");
+ _writer._counter.Add(0);
+ }
+
+ /// <summary>
+ /// Causes the end of the array character to be written.
+ /// </summary>
+ private void EndArray()
+ {
+ if (_writer != null)
+ {
+ _writer._counter.RemoveAt(_writer._counter.Count - 1);
+ _writer.WriteLine("]");
+ _writer.Flush();
+ }
+ _writer = null;
+ }
+
+ void IDisposable.Dispose()
+ {
+ EndArray();
+ }
+ }
+
+ /// <summary>
+ /// Used to write an array of messages as the output rather than a single message.
+ /// </summary>
+ /// <example>
+ /// <code>
+ /// using(writer.StartArray())
+ /// foreach(IMessageLite m in messages)
+ /// writer.WriteMessage(m);
+ /// </code>
+ /// </example>
+ public JsonArray StartArray()
+ {
+ if (_isArray)
+ {
+ Seperator();
+ }
+ _isArray = true;
+ return new JsonArray(this);
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/JsonTextCursor.cs b/csharp/src/ProtocolBuffers.Serialization/JsonTextCursor.cs
new file mode 100644
index 00000000..19c45af7
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/JsonTextCursor.cs
@@ -0,0 +1,442 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// JSon Tokenizer used by JsonFormatReader
+ /// </summary>
+ internal abstract class JsonCursor
+ {
+ public enum JsType
+ {
+ String,
+ Number,
+ Object,
+ Array,
+ True,
+ False,
+ Null
+ }
+
+ #region Buffering implementations
+
+ private class JsonStreamCursor : JsonCursor
+ {
+ private readonly byte[] _buffer;
+ private int _bufferPos;
+ private readonly Stream _input;
+
+ public JsonStreamCursor(Stream input)
+ {
+ _input = input;
+ _next = _input.ReadByte();
+ }
+
+ public JsonStreamCursor(byte[] input)
+ {
+ _input = null;
+ _buffer = input;
+ _next = _buffer[_bufferPos];
+ }
+
+ protected override int Peek()
+ {
+ if (_input != null)
+ {
+ return _next;
+ }
+ else if (_bufferPos < _buffer.Length)
+ {
+ return _buffer[_bufferPos];
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ protected override int Read()
+ {
+ if (_input != null)
+ {
+ int result = _next;
+ _next = _input.ReadByte();
+ return result;
+ }
+ else if (_bufferPos < _buffer.Length)
+ {
+ return _buffer[_bufferPos++];
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ }
+
+ private class JsonTextCursor : JsonCursor
+ {
+ private readonly char[] _buffer;
+ private int _bufferPos;
+ private readonly TextReader _input;
+
+ public JsonTextCursor(char[] input)
+ {
+ _input = null;
+ _buffer = input;
+ _bufferPos = 0;
+ _next = Peek();
+ }
+
+ public JsonTextCursor(TextReader input)
+ {
+ _input = input;
+ _next = Peek();
+ }
+
+ protected override int Peek()
+ {
+ if (_input != null)
+ {
+ return _input.Peek();
+ }
+ else if (_bufferPos < _buffer.Length)
+ {
+ return _buffer[_bufferPos];
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ protected override int Read()
+ {
+ if (_input != null)
+ {
+ return _input.Read();
+ }
+ else if (_bufferPos < _buffer.Length)
+ {
+ return _buffer[_bufferPos++];
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ }
+
+ #endregion
+
+ protected int _next;
+ private int _lineNo, _linePos;
+
+ public static JsonCursor CreateInstance(byte[] input)
+ {
+ return new JsonStreamCursor(input);
+ }
+
+ public static JsonCursor CreateInstance(Stream input)
+ {
+ return new JsonStreamCursor(input);
+ }
+
+ public static JsonCursor CreateInstance(string input)
+ {
+ return new JsonTextCursor(input.ToCharArray());
+ }
+
+ public static JsonCursor CreateInstance(TextReader input)
+ {
+ return new JsonTextCursor(input);
+ }
+
+ protected JsonCursor()
+ {
+ _lineNo = 1;
+ _linePos = 0;
+ }
+
+ /// <summary>Returns the next character without actually 'reading' it</summary>
+ protected abstract int Peek();
+
+ /// <summary>Reads the next character in the input</summary>
+ protected abstract int Read();
+
+ public Char NextChar
+ {
+ get
+ {
+ SkipWhitespace();
+ return (char) _next;
+ }
+ }
+
+ #region Assert(...)
+
+ [DebuggerNonUserCode]
+ private string CharDisplay(int ch)
+ {
+ return ch == -1
+ ? "EOF"
+ : (ch > 32 && ch < 127)
+ ? String.Format("'{0}'", (char) ch)
+ : String.Format("'\\u{0:x4}'", ch);
+ }
+
+ [DebuggerNonUserCode]
+ private void Assert(bool cond, char expected)
+ {
+ if (!cond)
+ {
+ throw new FormatException(
+ String.Format(FrameworkPortability.InvariantCulture,
+ "({0}:{1}) error: Unexpected token {2}, expected: {3}.",
+ _lineNo, _linePos,
+ CharDisplay(_next),
+ CharDisplay(expected)
+ ));
+ }
+ }
+
+ [DebuggerNonUserCode]
+ public void Assert(bool cond, string message)
+ {
+ if (!cond)
+ {
+ throw new FormatException(
+ String.Format(FrameworkPortability.InvariantCulture,
+ "({0},{1}) error: {2}", _lineNo, _linePos, message));
+ }
+ }
+
+ [DebuggerNonUserCode]
+ public void Assert(bool cond, string format, params object[] args)
+ {
+ if (!cond)
+ {
+ if (args != null && args.Length > 0)
+ {
+ format = String.Format(format, args);
+ }
+ throw new FormatException(
+ String.Format(FrameworkPortability.InvariantCulture,
+ "({0},{1}) error: {2}", _lineNo, _linePos, format));
+ }
+ }
+
+ #endregion
+
+ private char ReadChar()
+ {
+ int ch = Read();
+ Assert(ch != -1, "Unexpected end of file.");
+ if (ch == '\n')
+ {
+ _lineNo++;
+ _linePos = 0;
+ }
+ else if (ch != '\r')
+ {
+ _linePos++;
+ }
+ _next = Peek();
+ return (char) ch;
+ }
+
+ public void Consume(char ch)
+ {
+ Assert(TryConsume(ch), ch);
+ }
+
+ public bool TryConsume(char ch)
+ {
+ SkipWhitespace();
+ if (_next == ch)
+ {
+ ReadChar();
+ return true;
+ }
+ return false;
+ }
+
+ public void Consume(string sequence)
+ {
+ SkipWhitespace();
+
+ foreach (char ch in sequence)
+ {
+ Assert(ch == ReadChar(), "Expected token '{0}'.", sequence);
+ }
+ }
+
+ public void SkipWhitespace()
+ {
+ int chnext = _next;
+ while (chnext != -1)
+ {
+ if (!Char.IsWhiteSpace((char) chnext))
+ {
+ break;
+ }
+ ReadChar();
+ chnext = _next;
+ }
+ }
+
+ public string ReadString()
+ {
+ SkipWhitespace();
+ Consume('"');
+ List<Char> sb = new List<char>(100);
+ while (_next != '"')
+ {
+ if (_next == '\\')
+ {
+ Consume('\\'); //skip the escape
+ char ch = ReadChar();
+ switch (ch)
+ {
+ case 'b':
+ sb.Add('\b');
+ break;
+ case 'f':
+ sb.Add('\f');
+ break;
+ case 'n':
+ sb.Add('\n');
+ break;
+ case 'r':
+ sb.Add('\r');
+ break;
+ case 't':
+ sb.Add('\t');
+ break;
+ case 'u':
+ {
+ string hex = new string(new char[] {ReadChar(), ReadChar(), ReadChar(), ReadChar()});
+ int result;
+ Assert(
+ FrameworkPortability.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, FrameworkPortability.InvariantCulture,
+ out result),
+ "Expected a 4-character hex specifier.");
+ sb.Add((char) result);
+ break;
+ }
+ default:
+ sb.Add(ch);
+ break;
+ }
+ }
+ else
+ {
+ Assert(_next != '\n' && _next != '\r' && _next != '\f' && _next != -1, '"');
+ sb.Add(ReadChar());
+ }
+ }
+ Consume('"');
+ return new String(sb.ToArray());
+ }
+
+ public string ReadNumber()
+ {
+ SkipWhitespace();
+ List<Char> sb = new List<char>(24);
+ if (_next == '-')
+ {
+ sb.Add(ReadChar());
+ }
+ Assert(_next >= '0' && _next <= '9', "Expected a numeric type.");
+ while ((_next >= '0' && _next <= '9') || _next == '.')
+ {
+ sb.Add(ReadChar());
+ }
+ if (_next == 'e' || _next == 'E')
+ {
+ sb.Add(ReadChar());
+ if (_next == '-' || _next == '+')
+ {
+ sb.Add(ReadChar());
+ }
+ Assert(_next >= '0' && _next <= '9', "Expected a numeric type.");
+ while (_next >= '0' && _next <= '9')
+ {
+ sb.Add(ReadChar());
+ }
+ }
+ return new String(sb.ToArray());
+ }
+
+ public JsType ReadVariant(out object value)
+ {
+ SkipWhitespace();
+ switch (_next)
+ {
+ case 'n':
+ Consume("null");
+ value = null;
+ return JsType.Null;
+ case 't':
+ Consume("true");
+ value = true;
+ return JsType.True;
+ case 'f':
+ Consume("false");
+ value = false;
+ return JsType.False;
+ case '"':
+ value = ReadString();
+ return JsType.String;
+ case '{':
+ {
+ Consume('{');
+ while (NextChar != '}')
+ {
+ ReadString();
+ Consume(':');
+ object tmp;
+ ReadVariant(out tmp);
+ if (!TryConsume(','))
+ {
+ break;
+ }
+ }
+ Consume('}');
+ value = null;
+ return JsType.Object;
+ }
+ case '[':
+ {
+ Consume('[');
+ List<object> values = new List<object>();
+ while (NextChar != ']')
+ {
+ object tmp;
+ ReadVariant(out tmp);
+ values.Add(tmp);
+ if (!TryConsume(','))
+ {
+ break;
+ }
+ }
+ Consume(']');
+ value = values.ToArray();
+ return JsType.Array;
+ }
+ default:
+ if ((_next >= '0' && _next <= '9') || _next == '-')
+ {
+ value = ReadNumber();
+ return JsType.Number;
+ }
+ Assert(false, "Expected a value.");
+ throw new FormatException();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs b/csharp/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..c6420b56
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs
@@ -0,0 +1,67 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyTitle("ProtocolBuffers")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ProtocolBuffers")]
+[assembly: AssemblyCopyright("Copyright © 2008")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("2.4.1.555")]
+
+[assembly: AssemblyVersion("2.4.1.555")]
+
+#if !NOFILEVERSION
+[assembly: AssemblyFileVersion("2.4.1.555")]
+#endif
+
+[assembly: CLSCompliant(true)] \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF20.csproj
new file mode 100644
index 00000000..0639ec65
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF20.csproj
@@ -0,0 +1,104 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>COMPACT_FRAMEWORK</EnvironmentFlavor>
+ <EnvironmentTemplate>CF20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <PlatformFamilyName>Smartphone</PlatformFamilyName>
+ <PlatformID>f27da329-3269-4191-98e0-c87d3d7f1db9</PlatformID>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\CF20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\CF20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\CF20\Release</OutputPath>
+ <IntermediateOutputPath>obj\CF20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.CF20.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
+ <HostingProcess disable="1" />
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF35.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF35.csproj
new file mode 100644
index 00000000..22f381f9
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.CF35.csproj
@@ -0,0 +1,104 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>COMPACT_FRAMEWORK</EnvironmentFlavor>
+ <EnvironmentTemplate>CF35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <PlatformFamilyName>Smartphone</PlatformFamilyName>
+ <PlatformID>f27da329-3269-4191-98e0-c87d3d7f1db9</PlatformID>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\CF35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\CF35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\CF35\Release</OutputPath>
+ <IntermediateOutputPath>obj\CF35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.CF35.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
+ <HostingProcess disable="1" />
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET20.csproj
new file mode 100644
index 00000000..dfeab79c
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET20.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET20\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.NET20.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET35.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET35.csproj
new file mode 100644
index 00000000..4bed60d7
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET35.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET35\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.NET35.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET40.csproj
new file mode 100644
index 00000000..80b76a0e
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.NET40.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET40\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.NET40.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.PL40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.PL40.csproj
new file mode 100644
index 00000000..60f87748
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.PL40.csproj
@@ -0,0 +1,95 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>PORTABLE_LIBRARY</EnvironmentFlavor>
+ <EnvironmentTemplate>PL40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <TargetFrameworkProfile>Profile1</TargetFrameworkProfile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\PL40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\PL40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\PL40\Release</OutputPath>
+ <IntermediateOutputPath>obj\PL40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.PL40.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL20.csproj
new file mode 100644
index 00000000..f8c4c097
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL20.csproj
@@ -0,0 +1,107 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL20\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.SL20.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL30.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL30.csproj
new file mode 100644
index 00000000..376c4936
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL30.csproj
@@ -0,0 +1,107 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL30</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL30\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL30\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL30\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL30\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.SL30.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL40.csproj
new file mode 100644
index 00000000..dc675c47
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.SL40.csproj
@@ -0,0 +1,108 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ <SilverlightVersion>v4.0</SilverlightVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL40\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.SL40.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
new file mode 100644
index 00000000..b9f728b8
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET35\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF20.csproj
new file mode 100644
index 00000000..b382dc3e
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF20.csproj
@@ -0,0 +1,104 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>COMPACT_FRAMEWORK</EnvironmentFlavor>
+ <EnvironmentTemplate>CF20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <PlatformFamilyName>Smartphone</PlatformFamilyName>
+ <PlatformID>f27da329-3269-4191-98e0-c87d3d7f1db9</PlatformID>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\CF20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\CF20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\CF20\Release</OutputPath>
+ <IntermediateOutputPath>obj\CF20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.CF20.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
+ <HostingProcess disable="1" />
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF35.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF35.csproj
new file mode 100644
index 00000000..558931d5
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.CF35.csproj
@@ -0,0 +1,104 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>COMPACT_FRAMEWORK</EnvironmentFlavor>
+ <EnvironmentTemplate>CF35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <PlatformFamilyName>Smartphone</PlatformFamilyName>
+ <PlatformID>f27da329-3269-4191-98e0-c87d3d7f1db9</PlatformID>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\CF35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\CF35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\CF35\Release</OutputPath>
+ <IntermediateOutputPath>obj\CF35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOFILEVERSION</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.CF35.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
+ <HostingProcess disable="1" />
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET20.csproj
new file mode 100644
index 00000000..1e145abe
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET20.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET20\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.NET20.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET35.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET35.csproj
new file mode 100644
index 00000000..9fd744c5
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET35.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET35\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.NET35.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET40.csproj
new file mode 100644
index 00000000..1254fdf2
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.NET40.csproj
@@ -0,0 +1,92 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET40\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.NET40.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.PL40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.PL40.csproj
new file mode 100644
index 00000000..c6fbb6a7
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.PL40.csproj
@@ -0,0 +1,95 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>PORTABLE_LIBRARY</EnvironmentFlavor>
+ <EnvironmentTemplate>PL40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <TargetFrameworkProfile>Profile1</TargetFrameworkProfile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\PL40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\PL40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\PL40\Release</OutputPath>
+ <IntermediateOutputPath>obj\PL40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.PL40.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL20.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL20.csproj
new file mode 100644
index 00000000..9e891070
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL20.csproj
@@ -0,0 +1,107 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL20</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL20\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL20\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL20\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL20\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST;NOEXTENSIONS</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.SL20.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL30.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL30.csproj
new file mode 100644
index 00000000..6d3ac128
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL30.csproj
@@ -0,0 +1,107 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL30</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL30\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL30\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL30\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL30\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.SL30.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL40.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL40.csproj
new file mode 100644
index 00000000..9b341632
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.SL40.csproj
@@ -0,0 +1,108 @@
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:cs="urn:schemas-csharp-project:template">
+ <PropertyGroup>
+ <EnvironmentFlavor>SILVERLIGHT</EnvironmentFlavor>
+ <EnvironmentTemplate>SL40</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>false</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ <SilverlightVersion>v4.0</SilverlightVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\SL40\Debug</OutputPath>
+ <IntermediateOutputPath>obj\SL40\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\SL40\Release</OutputPath>
+ <IntermediateOutputPath>obj\SL40\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate);NOSERIALIZABLE;NOSORTEDLIST</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <NoConfig>true</NoConfig>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.SL40.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties>
+ <StartAction>OfflineApplication</StartAction>
+ </SilverlightProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.csproj b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.csproj
new file mode 100644
index 00000000..c1754cf2
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.csproj
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
+ <EnvironmentTemplate>NET35</EnvironmentTemplate>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\NET35\Debug</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Debug\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\NET35\Release</OutputPath>
+ <IntermediateOutputPath>obj\NET35\Release\</IntermediateOutputPath>
+ <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
+ <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
+ <DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
+ <Link>FrameworkPortability.cs</Link>
+ </Compile>
+ <Compile Include="Extensions.cs" />
+ <Compile Include="Http\FormUrlEncodedReader.cs" />
+ <Compile Include="Http\MessageFormatFactory.cs" />
+ <Compile Include="Http\MessageFormatOptions.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="AbstractReader.cs" />
+ <Compile Include="AbstractTextReader.cs" />
+ <Compile Include="AbstractTextWriter.cs" />
+ <Compile Include="AbstractWriter.cs" />
+ <Compile Include="DictionaryReader.cs" />
+ <Compile Include="DictionaryWriter.cs" />
+ <Compile Include="JsonFormatReader.cs" />
+ <Compile Include="JsonFormatWriter.cs" />
+ <Compile Include="JsonTextCursor.cs" />
+ <Compile Include="RecursionLimitExceeded.cs" />
+ <Compile Include="XmlFormatReader.cs" />
+ <Compile Include="XmlFormatWriter.cs" />
+ <Compile Include="XmlReaderOptions.cs" />
+ <Compile Include="XmlWriterOptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>False</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs b/csharp/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs
new file mode 100644
index 00000000..14e72ba8
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// The exception raised when a recursion limit is reached while parsing input.
+ /// </summary>
+ public sealed class RecursionLimitExceededException : FormatException
+ {
+ const string message = "Possible malicious message had too many levels of nesting.";
+
+ internal RecursionLimitExceededException() : base(message)
+ {
+ }
+ }
+}
diff --git a/csharp/src/ProtocolBuffers.Serialization/XmlFormatReader.cs b/csharp/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
new file mode 100644
index 00000000..a4f111d4
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
@@ -0,0 +1,338 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using System.Diagnostics;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Parses a proto buffer from an XML document or fragment. .NET 3.5 users may also
+ /// use this class to process Json by setting the options to support Json and providing
+ /// an XmlReader obtained from <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory"/>.
+ /// </summary>
+ public class XmlFormatReader : AbstractTextReader
+ {
+ public const string DefaultRootElementName = XmlFormatWriter.DefaultRootElementName;
+ private readonly XmlReader _input;
+ // Tracks the message element for each nested message read
+ private readonly Stack<ElementStackEntry> _elements;
+ // The default element name for ReadMessageStart
+ private string _rootElementName;
+
+ private struct ElementStackEntry
+ {
+ public readonly string LocalName;
+ public readonly int Depth;
+ public readonly bool IsEmpty;
+
+ public ElementStackEntry(string localName, int depth, bool isEmpty) : this()
+ {
+ LocalName = localName;
+ IsEmpty = isEmpty;
+ Depth = depth;
+ }
+ }
+
+ private static XmlReaderSettings DefaultSettings
+ {
+ get
+ {
+ return new XmlReaderSettings()
+ {CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true};
+ }
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader using the stream provided as the xml
+ /// </summary>
+ public static XmlFormatReader CreateInstance(byte[] input)
+ {
+ return new XmlFormatReader(XmlReader.Create(new MemoryStream(input, false), DefaultSettings));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader using the stream provided as the xml
+ /// </summary>
+ public static XmlFormatReader CreateInstance(Stream input)
+ {
+ return new XmlFormatReader(XmlReader.Create(input, DefaultSettings));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader using the string provided as the xml to be read
+ /// </summary>
+ public static XmlFormatReader CreateInstance(String input)
+ {
+ return new XmlFormatReader(XmlReader.Create(new StringReader(input), DefaultSettings));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader using the xml in the TextReader
+ /// </summary>
+ public static XmlFormatReader CreateInstance(TextReader input)
+ {
+ return new XmlFormatReader(XmlReader.Create(input, DefaultSettings));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader with the XmlReader
+ /// </summary>
+ public static XmlFormatReader CreateInstance(XmlReader input)
+ {
+ return new XmlFormatReader(input);
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatReader with the XmlReader and options
+ /// </summary>
+ protected XmlFormatReader(XmlReader input)
+ {
+ _input = input;
+ _rootElementName = DefaultRootElementName;
+ _elements = new Stack<ElementStackEntry>();
+ Options = XmlReaderOptions.None;
+ }
+
+ /// <summary>
+ /// Gets or sets the options to use when reading the xml
+ /// </summary>
+ public XmlReaderOptions Options { get; set; }
+
+ /// <summary>
+ /// Sets the options to use while generating the XML
+ /// </summary>
+ public XmlFormatReader SetOptions(XmlReaderOptions options)
+ {
+ Options = options;
+ return this;
+ }
+
+ /// <summary>
+ /// Gets or sets the default element name to use when using the Merge&lt;TBuilder>()
+ /// </summary>
+ public string RootElementName
+ {
+ get { return _rootElementName; }
+ set
+ {
+ ThrowHelper.ThrowIfNull(value, "RootElementName");
+ _rootElementName = value;
+ }
+ }
+
+ [DebuggerNonUserCode]
+ private static void Assert(bool cond)
+ {
+ if (!cond)
+ {
+ throw new FormatException();
+ }
+ }
+
+ /// <summary>
+ /// Reads the root-message preamble specific to this formatter
+ /// </summary>
+ public override void ReadMessageStart()
+ {
+ ReadMessageStart(_rootElementName);
+ }
+
+ /// <summary>
+ /// Reads the root-message preamble specific to this formatter
+ /// </summary>
+ public void ReadMessageStart(string element)
+ {
+ while (!_input.IsStartElement() && _input.Read())
+ {
+ continue;
+ }
+ Assert(_input.IsStartElement() && _input.LocalName == element);
+ _elements.Push(new ElementStackEntry(element, _input.Depth, _input.IsEmptyElement));
+ _input.Read();
+ }
+
+ /// <summary>
+ /// Reads the root-message close specific to this formatter, MUST be called
+ /// on the reader obtained from ReadMessageStart(string element).
+ /// </summary>
+ public override void ReadMessageEnd()
+ {
+ Assert(_elements.Count > 0);
+
+ ElementStackEntry stop = _elements.Peek();
+ while (_input.NodeType != XmlNodeType.EndElement && _input.NodeType != XmlNodeType.Element
+ && _input.Depth > stop.Depth && _input.Read())
+ {
+ continue;
+ }
+
+ if (!stop.IsEmpty)
+ {
+ Assert(_input.NodeType == XmlNodeType.EndElement
+ && _input.LocalName == stop.LocalName
+ && _input.Depth == stop.Depth);
+
+ _input.Read();
+ }
+ _elements.Pop();
+ }
+
+ /// <summary>
+ /// Merge the provided builder as an element named <see cref="RootElementName"/> in the current context
+ /// </summary>
+ public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
+ {
+ return Merge(_rootElementName, builder, registry);
+ }
+
+ /// <summary>
+ /// Merge the provided builder as an element of the current context
+ /// </summary>
+ public TBuilder Merge<TBuilder>(string element, TBuilder builder) where TBuilder : IBuilderLite
+ {
+ return Merge(element, builder, ExtensionRegistry.Empty);
+ }
+
+ /// <summary>
+ /// Merge the provided builder as an element of the current context
+ /// </summary>
+ public TBuilder Merge<TBuilder>(string element, TBuilder builder, ExtensionRegistry registry)
+ where TBuilder : IBuilderLite
+ {
+ ReadMessageStart(element);
+ builder.WeakMergeFrom(this, registry);
+ ReadMessageEnd();
+ return builder;
+ }
+
+ /// <summary>
+ /// Peeks at the next field in the input stream and returns what information is available.
+ /// </summary>
+ /// <remarks>
+ /// This may be called multiple times without actually reading the field. Only after the field
+ /// is either read, or skipped, should PeekNext return a different value.
+ /// </remarks>
+ protected override bool PeekNext(out string field)
+ {
+ ElementStackEntry stopNode;
+ if (_elements.Count == 0)
+ {
+ stopNode = new ElementStackEntry(null, _input.Depth - 1, false);
+ }
+ else
+ {
+ stopNode = _elements.Peek();
+ }
+
+ if (!stopNode.IsEmpty)
+ {
+ while (!_input.IsStartElement() && _input.Depth > stopNode.Depth && _input.Read())
+ {
+ continue;
+ }
+
+ if (_input.IsStartElement() && _input.Depth > stopNode.Depth)
+ {
+ field = _input.LocalName;
+ return true;
+ }
+ }
+ field = null;
+ return false;
+ }
+
+ /// <summary>
+ /// Causes the reader to skip past this field
+ /// </summary>
+ protected override void Skip()
+ {
+ if (_input.IsStartElement())
+ {
+ if (!_input.IsEmptyElement)
+ {
+ int depth = _input.Depth;
+ while (_input.Depth >= depth && _input.NodeType != XmlNodeType.EndElement)
+ {
+ Assert(_input.Read());
+ }
+ }
+ _input.Read();
+ }
+ }
+
+ /// <summary>
+ /// returns true if it was able to read a single value into the value reference. The value
+ /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
+ /// </summary>
+ protected override bool ReadEnum(ref object value)
+ {
+ int number;
+ string temp;
+ if (null != (temp = _input.GetAttribute("value")) && FrameworkPortability.TryParseInt32(temp, out number))
+ {
+ Skip();
+ value = number;
+ return true;
+ }
+ return base.ReadEnum(ref value);
+ }
+
+ /// <summary>
+ /// Returns true if it was able to read a String from the input
+ /// </summary>
+ protected override bool ReadAsText(ref string value, Type type)
+ {
+ Assert(_input.NodeType == XmlNodeType.Element);
+ value = _input.ReadElementContentAsString();
+
+ return true;
+ }
+
+ /// <summary>
+ /// Merges the input stream into the provided IBuilderLite
+ /// </summary>
+ protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
+ {
+ Assert(_input.IsStartElement());
+ ReadMessageStart(_input.LocalName);
+ builder.WeakMergeFrom(this, registry);
+ ReadMessageEnd();
+ return true;
+ }
+
+ private IEnumerable<string> NonNestedArrayItems(string field)
+ {
+ return base.ForeachArrayItem(field);
+ }
+
+ /// <summary>
+ /// Cursors through the array elements and stops at the end of the array
+ /// </summary>
+ protected override IEnumerable<string> ForeachArrayItem(string field)
+ {
+ bool isNested = (Options & XmlReaderOptions.ReadNestedArrays) != 0;
+
+ if (!isNested)
+ {
+ foreach (string item in NonNestedArrayItems(field))
+ {
+ yield return item;
+ }
+ }
+ else
+ {
+ string found;
+ ReadMessageStart(field);
+ if (PeekNext(out found) && found == "item")
+ {
+ foreach (string item in NonNestedArrayItems("item"))
+ {
+ yield return item;
+ }
+ }
+ ReadMessageEnd();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs b/csharp/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
new file mode 100644
index 00000000..4bd27562
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
@@ -0,0 +1,280 @@
+using System;
+using System.Collections;
+using System.IO;
+using System.Text;
+using System.Xml;
+using Google.ProtocolBuffers.Descriptors;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Writes a proto buffer to an XML document or fragment. .NET 3.5 users may also
+ /// use this class to produce Json by setting the options to support Json and providing
+ /// an XmlWriter obtained from <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory"/>.
+ /// </summary>
+ public class XmlFormatWriter : AbstractTextWriter
+ {
+ private static readonly Encoding DefaultEncoding = new UTF8Encoding(false);
+ public const string DefaultRootElementName = "root";
+
+ private readonly XmlWriter _output;
+ // The default element name used for WriteMessageStart
+ private string _rootElementName;
+ // Used to assert matching WriteMessageStart/WriteMessageEnd calls
+ private int _messageOpenCount;
+
+ private static XmlWriterSettings DefaultSettings(Encoding encoding)
+ {
+ return new XmlWriterSettings()
+ {
+ CheckCharacters = false,
+ NewLineHandling = NewLineHandling.Entitize,
+ OmitXmlDeclaration = true,
+ Encoding = encoding,
+ };
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatWriter to write to the given TextWriter
+ /// </summary>
+ public static XmlFormatWriter CreateInstance(TextWriter output)
+ {
+ return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(output.Encoding)));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatWriter to write to the given stream
+ /// </summary>
+ public static XmlFormatWriter CreateInstance(Stream output)
+ {
+ return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(DefaultEncoding)));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatWriter to write to the given stream
+ /// </summary>
+ public static XmlFormatWriter CreateInstance(Stream output, Encoding encoding)
+ {
+ return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(encoding)));
+ }
+
+ /// <summary>
+ /// Constructs the XmlFormatWriter to write to the given XmlWriter
+ /// </summary>
+ public static XmlFormatWriter CreateInstance(XmlWriter output)
+ {
+ return new XmlFormatWriter(output);
+ }
+
+ protected XmlFormatWriter(XmlWriter output)
+ {
+ _output = output;
+ _messageOpenCount = 0;
+ _rootElementName = DefaultRootElementName;
+ }
+
+ /// <summary>
+ /// Gets or sets the default element name to use when using the Merge&lt;TBuilder>()
+ /// </summary>
+ public string RootElementName
+ {
+ get { return _rootElementName; }
+ set
+ {
+ ThrowHelper.ThrowIfNull(value, "RootElementName");
+ _rootElementName = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the options to use while generating the XML
+ /// </summary>
+ public XmlWriterOptions Options { get; set; }
+
+ /// <summary>
+ /// Sets the options to use while generating the XML
+ /// </summary>
+ public XmlFormatWriter SetOptions(XmlWriterOptions options)
+ {
+ Options = options;
+ return this;
+ }
+
+ private bool TestOption(XmlWriterOptions option)
+ {
+ return (Options & option) != 0;
+ }
+
+ /// <summary>
+ /// Completes any pending write operations
+ /// </summary>
+ public override void Flush()
+ {
+ _output.Flush();
+ base.Flush();
+ }
+
+ /// <summary>
+ /// Used to write the root-message preamble, in xml this is open element for RootElementName,
+ /// by default "&lt;root&gt;". After this call you can call IMessageLite.MergeTo(...) and
+ /// complete the message with a call to WriteMessageEnd().
+ /// </summary>
+ public override void WriteMessageStart()
+ {
+ WriteMessageStart(_rootElementName);
+ }
+
+ /// <summary>
+ /// Used to write the root-message preamble, in xml this is open element for elementName.
+ /// After this call you can call IMessageLite.MergeTo(...) and complete the message with
+ /// a call to WriteMessageEnd().
+ /// </summary>
+ public void WriteMessageStart(string elementName)
+ {
+ if (TestOption(XmlWriterOptions.OutputJsonTypes))
+ {
+ _output.WriteStartElement("root"); // json requires this is the root-element
+ _output.WriteAttributeString("type", "object");
+ }
+ else
+ {
+ _output.WriteStartElement(elementName);
+ }
+ _messageOpenCount++;
+ }
+
+ /// <summary>
+ /// Used to complete a root-message previously started with a call to WriteMessageStart()
+ /// </summary>
+ public override void WriteMessageEnd()
+ {
+ if (_messageOpenCount <= 0)
+ {
+ throw new InvalidOperationException();
+ }
+
+ _output.WriteEndElement();
+ _output.Flush();
+ _messageOpenCount--;
+ }
+
+ /// <summary>
+ /// Writes a message as an element using the name defined in <see cref="RootElementName"/>
+ /// </summary>
+ public override void WriteMessage(IMessageLite message)
+ {
+ WriteMessage(_rootElementName, message);
+ }
+
+ /// <summary>
+ /// Writes a message as an element with the given name
+ /// </summary>
+ public void WriteMessage(string elementName, IMessageLite message)
+ {
+ WriteMessageStart(elementName);
+ message.WriteTo(this);
+ WriteMessageEnd();
+ }
+
+ /// <summary>
+ /// Writes a message
+ /// </summary>
+ protected override void WriteMessageOrGroup(string field, IMessageLite message)
+ {
+ _output.WriteStartElement(field);
+
+ if (TestOption(XmlWriterOptions.OutputJsonTypes))
+ {
+ _output.WriteAttributeString("type", "object");
+ }
+
+ message.WriteTo(this);
+ _output.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Writes a String value
+ /// </summary>
+ protected override void WriteAsText(string field, string textValue, object typedValue)
+ {
+ _output.WriteStartElement(field);
+
+ if (TestOption(XmlWriterOptions.OutputJsonTypes))
+ {
+ if (typedValue is int || typedValue is uint || typedValue is long || typedValue is ulong ||
+ typedValue is double || typedValue is float)
+ {
+ _output.WriteAttributeString("type", "number");
+ }
+ else if (typedValue is bool)
+ {
+ _output.WriteAttributeString("type", "boolean");
+ }
+ }
+ _output.WriteString(textValue);
+
+ //Empty strings should not be written as empty elements '<item/>', rather as '<item></item>'
+ if (_output.WriteState == WriteState.Element)
+ {
+ _output.WriteRaw("");
+ }
+
+ _output.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Writes an array of field values
+ /// </summary>
+ protected override void WriteArray(FieldType fieldType, string field, IEnumerable items)
+ {
+ //see if it's empty
+ IEnumerator eitems = items.GetEnumerator();
+ try
+ {
+ if (!eitems.MoveNext())
+ {
+ return;
+ }
+ }
+ finally
+ {
+ if (eitems is IDisposable)
+ {
+ ((IDisposable) eitems).Dispose();
+ }
+ }
+
+ if (TestOption(XmlWriterOptions.OutputNestedArrays | XmlWriterOptions.OutputJsonTypes))
+ {
+ _output.WriteStartElement(field);
+ if (TestOption(XmlWriterOptions.OutputJsonTypes))
+ {
+ _output.WriteAttributeString("type", "array");
+ }
+
+ base.WriteArray(fieldType, "item", items);
+ _output.WriteEndElement();
+ }
+ else
+ {
+ base.WriteArray(fieldType, field, items);
+ }
+ }
+
+ /// <summary>
+ /// Writes a System.Enum by the numeric and textual value
+ /// </summary>
+ protected override void WriteEnum(string field, int number, string name)
+ {
+ _output.WriteStartElement(field);
+
+ if (!TestOption(XmlWriterOptions.OutputJsonTypes) && TestOption(XmlWriterOptions.OutputEnumValues))
+ {
+ _output.WriteAttributeString("value", XmlConvert.ToString(number));
+ }
+
+ _output.WriteString(name);
+ _output.WriteEndElement();
+ }
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/XmlReaderOptions.cs b/csharp/src/ProtocolBuffers.Serialization/XmlReaderOptions.cs
new file mode 100644
index 00000000..f7eca1d7
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/XmlReaderOptions.cs
@@ -0,0 +1,17 @@
+using System;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Options available for the xml reader output
+ /// </summary>
+ [Flags]
+ public enum XmlReaderOptions
+ {
+ /// <summary> Simple xml formatting with no attributes </summary>
+ None,
+
+ /// <summary> Requires that arrays items are nested in an &lt;item> element </summary>
+ ReadNestedArrays = 1,
+ }
+} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers.Serialization/XmlWriterOptions.cs b/csharp/src/ProtocolBuffers.Serialization/XmlWriterOptions.cs
new file mode 100644
index 00000000..7d740ee3
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Serialization/XmlWriterOptions.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace Google.ProtocolBuffers.Serialization
+{
+ /// <summary>
+ /// Options available for the xml writer output
+ /// </summary>
+ [Flags]
+ public enum XmlWriterOptions
+ {
+ /// <summary> Simple xml formatting with no attributes </summary>
+ None,
+
+ /// <summary> Writes the 'value' attribute on all enumerations with the numeric identifier </summary>
+ OutputEnumValues = 0x1,
+
+ /// <summary> Embeds array items into child &lt;item> elements </summary>
+ OutputNestedArrays = 0x4,
+
+ /// <summary> Outputs the 'type' attribute for compatibility with the <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory">JsonReaderWriterFactory</see> </summary>
+ /// <remarks> This option must, by nessessity, also enable NestedArrayItems </remarks>
+ OutputJsonTypes = 0x8,
+ }
+} \ No newline at end of file