aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2009-09-09 13:58:01 +0100
committerJon Skeet <skeet@pobox.com>2009-09-09 13:58:01 +0100
commit8a5c7e792aac055962d6288ef241b5bae26af26b (patch)
tree8c8eff8f4cc0323950a7aaa616ca3d1c70a18c01 /src
parent3c80886fa9043cba3b0ecc0362935b014066b89f (diff)
downloadprotobuf-8a5c7e792aac055962d6288ef241b5bae26af26b.tar.gz
protobuf-8a5c7e792aac055962d6288ef241b5bae26af26b.tar.bz2
protobuf-8a5c7e792aac055962d6288ef241b5bae26af26b.zip
Silverlight compatibility now working, although build files aren't ideal
Diffstat (limited to 'src')
-rw-r--r--src/ProtocolBuffers.sln17
-rw-r--r--src/ProtocolBuffers/ProtocolBuffers.csproj19
-rw-r--r--src/ProtocolBuffers/SortedDictionary.cs157
3 files changed, 190 insertions, 3 deletions
diff --git a/src/ProtocolBuffers.sln b/src/ProtocolBuffers.sln
index cdcb2dbb..52887149 100644
--- a/src/ProtocolBuffers.sln
+++ b/src/ProtocolBuffers.sln
@@ -21,40 +21,57 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
+ Silverlight2|Any CPU = Silverlight2|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Silverlight2|Any CPU.ActiveCfg = Silverlight2|Any CPU
+ {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Silverlight2|Any CPU.Build.0 = Silverlight2|Any CPU
{DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DD01ED24-3750-4567-9A23-1DB676A15610}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {DD01ED24-3750-4567-9A23-1DB676A15610}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {250ADE34-82FD-4BAE-86D5-985FBE589C4A}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{C268DA4C-4004-47DA-AF23-44C983281A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C268DA4C-4004-47DA-AF23-44C983281A68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C268DA4C-4004-47DA-AF23-44C983281A68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C268DA4C-4004-47DA-AF23-44C983281A68}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C268DA4C-4004-47DA-AF23-44C983281A68}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {C268DA4C-4004-47DA-AF23-44C983281A68}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{8F09AF72-3327-4FA7-BC09-070B80221AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F09AF72-3327-4FA7-BC09-070B80221AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F09AF72-3327-4FA7-BC09-070B80221AB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F09AF72-3327-4FA7-BC09-070B80221AB9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8F09AF72-3327-4FA7-BC09-070B80221AB9}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {8F09AF72-3327-4FA7-BC09-070B80221AB9}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{C7A4A435-2813-41C8-AA87-BD914BA5223D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7A4A435-2813-41C8-AA87-BD914BA5223D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7A4A435-2813-41C8-AA87-BD914BA5223D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7A4A435-2813-41C8-AA87-BD914BA5223D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C7A4A435-2813-41C8-AA87-BD914BA5223D}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {C7A4A435-2813-41C8-AA87-BD914BA5223D}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
+ {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/ProtocolBuffers/ProtocolBuffers.csproj b/src/ProtocolBuffers/ProtocolBuffers.csproj
index 89676915..c58ac125 100644
--- a/src/ProtocolBuffers/ProtocolBuffers.csproj
+++ b/src/ProtocolBuffers/ProtocolBuffers.csproj
@@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -31,11 +32,20 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Silverlight2|AnyCPU' ">
+ <OutputPath>bin\Silverlight2\</OutputPath>
+ <DefineConstants>TRACE;SILVERLIGHT2</DefineConstants>
+ <Optimize>true</Optimize>
+ <NoStdLib>true</NoStdLib>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="mscorlib" />
<Reference Include="System" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractBuilder.cs" />
@@ -103,6 +113,8 @@
<Compile Include="NameHelpers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RpcUtil.cs" />
+ <Compile Include="SilverlightCompatibility.cs" />
+ <Compile Include="SortedDictionary.cs" />
<Compile Include="TextFormat.cs" />
<Compile Include="TextGenerator.cs" />
<Compile Include="TextTokenizer.cs" />
@@ -115,7 +127,8 @@
<ItemGroup>
<None Include="Properties\Google.ProtocolBuffers.snk" />
</ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(Configuration)' != 'Silverlight2' " />
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" Condition=" '$(Configuration)' == 'Silverlight2' " />
<!-- 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">
diff --git a/src/ProtocolBuffers/SortedDictionary.cs b/src/ProtocolBuffers/SortedDictionary.cs
new file mode 100644
index 00000000..bb0a1411
--- /dev/null
+++ b/src/ProtocolBuffers/SortedDictionary.cs
@@ -0,0 +1,157 @@
+// 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.
+#if SILVERLIGHT2
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.ProtocolBuffers
+{
+ /// <summary>
+ /// Dictionary implementation which always yields keys in sorted order.
+ /// This is not particularly efficient: it wraps a normal dictionary
+ /// for most operations, but sorts by key when either iterating or
+ /// fetching the Keys/Values properties.
+ /// This is only used for Silverlight, which doesn't have the normal
+ /// sorted collections.
+ /// </summary>
+ internal sealed class SortedDictionary<TKey, TValue> : IDictionary<TKey, TValue>
+ {
+ private readonly IDictionary<TKey, TValue> wrapped = new Dictionary<TKey, TValue>();
+
+ public void Add(TKey key, TValue value)
+ {
+ wrapped.Add(key, value);
+ }
+
+ public bool ContainsKey(TKey key)
+ {
+ return wrapped.ContainsKey(key);
+ }
+
+ public ICollection<TKey> Keys
+ {
+ get
+ {
+ List<TKey> keys = new List<TKey>(wrapped.Count);
+ foreach (var pair in this)
+ {
+ keys.Add(pair.Key);
+ }
+ return keys;
+ }
+ }
+
+ public bool Remove(TKey key)
+ {
+ return wrapped.Remove(key);
+ }
+
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ return wrapped.TryGetValue(key, out value);
+ }
+
+ public ICollection<TValue> Values
+ {
+ get
+ {
+ List<TValue> values = new List<TValue>(wrapped.Count);
+ foreach (var pair in this)
+ {
+ values.Add(pair.Value);
+ }
+ return values;
+ }
+ }
+
+ public TValue this[TKey key]
+ {
+ get
+ {
+ return wrapped[key];
+ }
+ set
+ {
+ wrapped[key] = value;
+ }
+ }
+
+ public void Add(KeyValuePair<TKey, TValue> item)
+ {
+ wrapped.Add(item);
+ }
+
+ public void Clear()
+ {
+ wrapped.Clear();
+ }
+
+ public bool Contains(KeyValuePair<TKey, TValue> item)
+ {
+ return wrapped.Contains(item);
+ }
+
+ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
+ {
+ wrapped.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return wrapped.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return wrapped.IsReadOnly; }
+ }
+
+ public bool Remove(KeyValuePair<TKey, TValue> item)
+ {
+ return wrapped.Remove(item);
+ }
+
+ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
+ {
+ IComparer<TKey> comparer = Comparer<TKey>.Default;
+ var list = new List<KeyValuePair<TKey, TValue>>(wrapped);
+ list.Sort((x, y) => comparer.Compare(x.Key, y.Key));
+ return list.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+}
+#endif \ No newline at end of file