THRIFT-309. Make Thrift's C# mapping .NET 2.0 (Mono 1.2.4) compatible
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@743963 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/csharp/Makefile.am b/lib/csharp/Makefile.am
index 710cd12..4ceb9e0 100644
--- a/lib/csharp/Makefile.am
+++ b/lib/csharp/Makefile.am
@@ -1,4 +1,5 @@
THRIFTCODE= \
+ src/Collections/THashSet.cs \
src/Protocol/TBase.cs \
src/Protocol/TProtocolException.cs \
src/Protocol/TProtocolFactory.cs \
@@ -31,10 +32,14 @@
CSC=gmcs
+if NET_2_0
+MONO_DEFINES=/d:NET_2_0
+endif
+
all-local: Thrift.dll
Thrift.dll: $(THRIFTCODE)
- $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library /langversion:linq
+ $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library $(MONO_DEFINES)
clean-local:
$(RM) Thrift.dll
diff --git a/lib/csharp/src/Collections/THashSet.cs b/lib/csharp/src/Collections/THashSet.cs
new file mode 100644
index 0000000..51a09b5
--- /dev/null
+++ b/lib/csharp/src/Collections/THashSet.cs
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Thrift.Collections
+{
+ public class THashSet<T> : ICollection<T>
+ {
+#if NET_2_0
+ TDictSet<T> set = new TDictSet<T>();
+#else
+ HashSet<T> set = new HashSet<T>();
+#endif
+ public int Count
+ {
+ get { return set.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return set.IsReadOnly; }
+ }
+
+ public void Add(T item)
+ {
+ set.Add(item);
+ }
+
+ public void Clear()
+ {
+ set.Clear();
+ }
+
+ public bool Contains(T item)
+ {
+ return set.Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ set.CopyTo(array, arrayIndex);
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return set.GetEnumerator();
+ }
+
+ IEnumerator<T> IEnumerable<T>.GetEnumerator()
+ {
+ return ((IEnumerable<T>)set).GetEnumerator();
+ }
+
+ public bool Remove(T item)
+ {
+ return set.Remove(item);
+ }
+
+#if NET_2_0
+ private class TDictSet<V> : ICollection<V>
+ {
+ Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>();
+
+ public int Count
+ {
+ get { return dict.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return ((IEnumerable)dict.Keys).GetEnumerator();
+ }
+
+ IEnumerator<V> IEnumerable<V>.GetEnumerator()
+ {
+ return dict.Keys.GetEnumerator();
+ }
+
+ public bool Add(V item)
+ {
+ if (!dict.ContainsKey(item))
+ {
+ dict[item] = this;
+ return true;
+ }
+
+ return false;
+ }
+
+ void ICollection<V>.Add(V item)
+ {
+ Add(item);
+ }
+
+ public void Clear()
+ {
+ dict.Clear();
+ }
+
+ public bool Contains(V item)
+ {
+ return dict.ContainsKey(item);
+ }
+
+ public void CopyTo(V[] array, int arrayIndex)
+ {
+ dict.Keys.CopyTo(array, arrayIndex);
+ }
+
+ public bool Remove(V item)
+ {
+ return dict.Remove(item);
+ }
+ }
+#endif
+ }
+
+}
diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs
index 5df2021..2f2f4a1 100644
--- a/lib/csharp/src/Protocol/TBinaryProtocol.cs
+++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs
@@ -12,7 +12,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
using System.Text;
using Thrift.Transport;
diff --git a/lib/csharp/src/Protocol/TField.cs b/lib/csharp/src/Protocol/TField.cs
index 93c0738..bda1760 100644
--- a/lib/csharp/src/Protocol/TField.cs
+++ b/lib/csharp/src/Protocol/TField.cs
@@ -18,30 +18,34 @@
{
public struct TField
{
+ private string name;
+ private TType type;
+ private short id;
+
public TField(string name, TType type, short id)
:this()
{
- Name = name;
- Type = type;
- ID = id;
+ this.name = name;
+ this.type = type;
+ this.id = id;
}
public string Name
{
- get;
- set;
+ get { return name; }
+ set { name = value; }
}
public TType Type
{
- get;
- set;
+ get { return type; }
+ set { type = value; }
}
public short ID
{
- get;
- set;
+ get { return id; }
+ set { id = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TList.cs b/lib/csharp/src/Protocol/TList.cs
index ccce522..5e4fa39 100644
--- a/lib/csharp/src/Protocol/TList.cs
+++ b/lib/csharp/src/Protocol/TList.cs
@@ -18,23 +18,26 @@
{
public struct TList
{
+ private TType elementType;
+ private int count;
+
public TList(TType elementType, int count)
:this()
{
- ElementType = elementType;
- Count = count;
+ this.elementType = elementType;
+ this.count = count;
}
public TType ElementType
{
- get;
- set;
+ get { return elementType; }
+ set { elementType = value; }
}
public int Count
{
- get;
- set;
+ get { return count; }
+ set { count = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TMap.cs b/lib/csharp/src/Protocol/TMap.cs
index a71e52a..4813027 100644
--- a/lib/csharp/src/Protocol/TMap.cs
+++ b/lib/csharp/src/Protocol/TMap.cs
@@ -18,30 +18,34 @@
{
public struct TMap
{
+ private TType keyType;
+ private TType valueType;
+ private int count;
+
public TMap(TType keyType, TType valueType, int count)
:this()
{
- KeyType = keyType;
- ValueType = valueType;
- Count = count;
+ this.keyType = keyType;
+ this.valueType = valueType;
+ this.count = count;
}
public TType KeyType
{
- get;
- set;
+ get { return keyType; }
+ set { keyType = value; }
}
public TType ValueType
{
- get;
- set;
+ get { return valueType; }
+ set { valueType = value; }
}
public int Count
{
- get;
- set;
+ get { return count; }
+ set { count = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TMessage.cs b/lib/csharp/src/Protocol/TMessage.cs
index 15dfce0..3818da0 100644
--- a/lib/csharp/src/Protocol/TMessage.cs
+++ b/lib/csharp/src/Protocol/TMessage.cs
@@ -18,30 +18,34 @@
{
public struct TMessage
{
+ private string name;
+ private TMessageType type;
+ private int seqID;
+
public TMessage(string name, TMessageType type, int seqid)
:this()
{
- Name = name;
- Type = type;
- SeqID = seqid;
+ this.name = name;
+ this.type = type;
+ this.seqID = seqid;
}
public string Name
{
- get;
- set;
+ get { return name; }
+ set { name = value; }
}
public TMessageType Type
{
- get;
- set;
+ get { return type; }
+ set { type = value; }
}
public int SeqID
{
- get;
- set;
+ get { return seqID; }
+ set { seqID = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TMessageType.cs b/lib/csharp/src/Protocol/TMessageType.cs
index 6e6ead7..d458d53 100644
--- a/lib/csharp/src/Protocol/TMessageType.cs
+++ b/lib/csharp/src/Protocol/TMessageType.cs
@@ -11,8 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Protocol
{
diff --git a/lib/csharp/src/Protocol/TProtocol.cs b/lib/csharp/src/Protocol/TProtocol.cs
index 2702ad8..6e48fac 100644
--- a/lib/csharp/src/Protocol/TProtocol.cs
+++ b/lib/csharp/src/Protocol/TProtocol.cs
@@ -11,7 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
using System.Text;
using Thrift.Transport;
diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs
index db38d88..f43a7cc 100644
--- a/lib/csharp/src/Protocol/TProtocolException.cs
+++ b/lib/csharp/src/Protocol/TProtocolException.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Protocol
{
diff --git a/lib/csharp/src/Protocol/TProtocolFactory.cs b/lib/csharp/src/Protocol/TProtocolFactory.cs
index 756bb5e..4e15bb1 100644
--- a/lib/csharp/src/Protocol/TProtocolFactory.cs
+++ b/lib/csharp/src/Protocol/TProtocolFactory.cs
@@ -10,8 +10,6 @@
// See accompanying file LICENSE or visit the Thrift site at:
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
using Thrift.Transport;
namespace Thrift.Protocol
diff --git a/lib/csharp/src/Protocol/TProtocolUtil.cs b/lib/csharp/src/Protocol/TProtocolUtil.cs
index a65ea0f..577182c 100644
--- a/lib/csharp/src/Protocol/TProtocolUtil.cs
+++ b/lib/csharp/src/Protocol/TProtocolUtil.cs
@@ -11,8 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Protocol
{
diff --git a/lib/csharp/src/Protocol/TSet.cs b/lib/csharp/src/Protocol/TSet.cs
index 0bfc29e..cdf3849 100644
--- a/lib/csharp/src/Protocol/TSet.cs
+++ b/lib/csharp/src/Protocol/TSet.cs
@@ -18,23 +18,26 @@
{
public struct TSet
{
+ private TType elementType;
+ private int count;
+
public TSet(TType elementType, int count)
:this()
{
- ElementType = elementType;
- Count = count;
+ this.elementType = elementType;
+ this.count = count;
}
public TType ElementType
{
- get;
- set;
+ get { return elementType; }
+ set { elementType = value; }
}
public int Count
{
- get;
- set;
+ get { return count; }
+ set { count = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TStruct.cs b/lib/csharp/src/Protocol/TStruct.cs
index 62f60fd..1a7d572 100644
--- a/lib/csharp/src/Protocol/TStruct.cs
+++ b/lib/csharp/src/Protocol/TStruct.cs
@@ -17,16 +17,18 @@
{
public struct TStruct
{
+ private string name;
+
public TStruct(string name)
:this()
{
- Name = name;
+ this.name = name;
}
public string Name
{
- get;
- set;
+ get { return name; }
+ set { name = value; }
}
}
}
diff --git a/lib/csharp/src/Protocol/TType.cs b/lib/csharp/src/Protocol/TType.cs
index 257ac6b..5cc6178 100644
--- a/lib/csharp/src/Protocol/TType.cs
+++ b/lib/csharp/src/Protocol/TType.cs
@@ -11,8 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Protocol
{
diff --git a/lib/csharp/src/Server/TServer.cs b/lib/csharp/src/Server/TServer.cs
index afb2b9f..f5f617a 100644
--- a/lib/csharp/src/Server/TServer.cs
+++ b/lib/csharp/src/Server/TServer.cs
@@ -11,7 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
using Thrift.Protocol;
using Thrift.Transport;
using System.IO;
diff --git a/lib/csharp/src/Server/TSimpleServer.cs b/lib/csharp/src/Server/TSimpleServer.cs
index 95f3962..912b4a3 100644
--- a/lib/csharp/src/Server/TSimpleServer.cs
+++ b/lib/csharp/src/Server/TSimpleServer.cs
@@ -10,8 +10,6 @@
// See accompanying file LICENSE or visit the Thrift site at:
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
using Thrift.Transport;
using Thrift.Protocol;
diff --git a/lib/csharp/src/Server/TThreadPoolServer.cs b/lib/csharp/src/Server/TThreadPoolServer.cs
index b44487f..e3c5cde 100644
--- a/lib/csharp/src/Server/TThreadPoolServer.cs
+++ b/lib/csharp/src/Server/TThreadPoolServer.cs
@@ -10,8 +10,6 @@
// See accompanying file LICENSE or visit the Thrift site at:
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading;
using Thrift.Protocol;
using Thrift.Transport;
diff --git a/lib/csharp/src/Server/TThreadedServer.cs b/lib/csharp/src/Server/TThreadedServer.cs
index a4d33a5..2928f31 100644
--- a/lib/csharp/src/Server/TThreadedServer.cs
+++ b/lib/csharp/src/Server/TThreadedServer.cs
@@ -11,8 +11,8 @@
// http://developers.facebook.com/thrift/using
using System;
using System.Collections.Generic;
-using System.Text;
using System.Threading;
+using Thrift.Collections;
using Thrift.Protocol;
using Thrift.Transport;
@@ -28,7 +28,7 @@
private readonly int maxThreads;
private Queue<TTransport> clientQueue;
- private HashSet<Thread> clientThreads;
+ private THashSet<Thread> clientThreads;
private object clientLock;
private Thread workerThread;
@@ -73,7 +73,7 @@
this.maxThreads = maxThreads;
clientQueue = new Queue<TTransport>();
clientLock = new object();
- clientThreads = new HashSet<Thread>();
+ clientThreads = new THashSet<Thread>();
}
/// <summary>
diff --git a/lib/csharp/src/TApplicationException.cs b/lib/csharp/src/TApplicationException.cs
index 4248664..cb3353b 100644
--- a/lib/csharp/src/TApplicationException.cs
+++ b/lib/csharp/src/TApplicationException.cs
@@ -11,8 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
using Thrift.Protocol;
namespace Thrift
diff --git a/lib/csharp/src/TProcessor.cs b/lib/csharp/src/TProcessor.cs
index 2cbddd7..679e3f6 100644
--- a/lib/csharp/src/TProcessor.cs
+++ b/lib/csharp/src/TProcessor.cs
@@ -11,8 +11,6 @@
// http://developers.facebook.com/thrift/using
using System;
-using System.Collections.Generic;
-using System.Text;
using Thrift.Protocol;
namespace Thrift
diff --git a/lib/csharp/src/Thrift.csproj b/lib/csharp/src/Thrift.csproj
index 9f3f620..1eb4355 100644
--- a/lib/csharp/src/Thrift.csproj
+++ b/lib/csharp/src/Thrift.csproj
@@ -38,14 +38,9 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="System.Drawing" />
- <Reference Include="System.Windows.Forms" />
- <Reference Include="System.Xml" />
- <Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Collections\THashSet.cs" />
<Compile Include="Protocol\TBase.cs" />
<Compile Include="Protocol\TBinaryProtocol.cs" />
<Compile Include="Protocol\TField.cs" />
diff --git a/lib/csharp/src/Transport/TBufferedTransport.cs b/lib/csharp/src/Transport/TBufferedTransport.cs
index 96a0741..bd4ba95 100644
--- a/lib/csharp/src/Transport/TBufferedTransport.cs
+++ b/lib/csharp/src/Transport/TBufferedTransport.cs
@@ -7,9 +7,6 @@
//
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.IO;
namespace Thrift.Transport
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index a6caf90..3559ce7 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -9,8 +9,6 @@
// All rights reserved.
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Net.Sockets;
diff --git a/lib/csharp/src/Transport/TServerTransport.cs b/lib/csharp/src/Transport/TServerTransport.cs
index 6b05a15..bff62e1 100644
--- a/lib/csharp/src/Transport/TServerTransport.cs
+++ b/lib/csharp/src/Transport/TServerTransport.cs
@@ -8,8 +8,6 @@
// Copyright (C) 2007 imeem, inc. <http://www.imeem.com>
// All rights reserved.
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Transport
{
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index c790fce..cc7eefd 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -10,8 +10,6 @@
//
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Net.Sockets;
namespace Thrift.Transport
diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs
index ca14ecf..f74f59a 100644
--- a/lib/csharp/src/Transport/TStreamTransport.cs
+++ b/lib/csharp/src/Transport/TStreamTransport.cs
@@ -10,8 +10,6 @@
//
using System;
-using System.Collections.Generic;
-using System.Text;
using System.IO;
namespace Thrift.Transport
diff --git a/lib/csharp/src/Transport/TTransport.cs b/lib/csharp/src/Transport/TTransport.cs
index 915cbc9..c95d98e 100644
--- a/lib/csharp/src/Transport/TTransport.cs
+++ b/lib/csharp/src/Transport/TTransport.cs
@@ -10,8 +10,6 @@
//
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Transport
{
diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs
index daf21d8..fa1f6b5 100644
--- a/lib/csharp/src/Transport/TTransportException.cs
+++ b/lib/csharp/src/Transport/TTransportException.cs
@@ -10,8 +10,6 @@
//
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Thrift.Transport
{
diff --git a/lib/csharp/src/Transport/TTransportFactory.cs b/lib/csharp/src/Transport/TTransportFactory.cs
index a0a6c2b..0280649 100644
--- a/lib/csharp/src/Transport/TTransportFactory.cs
+++ b/lib/csharp/src/Transport/TTransportFactory.cs
@@ -9,9 +9,6 @@
// All rights reserved.
//
using System;
-using System.Collections.Generic;
-using System.Text;
-
namespace Thrift.Transport
{