Author: roger
Date: Wed Sep 19 19:30:36 2012
New Revision: 1387715

URL: http://svn.apache.org/viewvc?rev=1387715&view=rev
Log:
THRIFT-1694 Re-Enable serialization for WP7 Silverlight 
Patch: Jens Geyer

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_csharp_generator.cc
    thrift/trunk/lib/csharp/src/Collections/THashSet.cs

Modified: thrift/trunk/compiler/cpp/src/generate/t_csharp_generator.cc
URL: 
http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_csharp_generator.cc?rev=1387715&r1=1387714&r2=1387715&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_csharp_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_csharp_generator.cc Wed Sep 19 
19:30:36 2012
@@ -50,6 +50,12 @@ class t_csharp_generator : public t_oop_
       iter = parsed_options.find("async");
       async_ctp_ = (iter != parsed_options.end());
 
+      iter = parsed_options.find("serial");
+      serialize_ = (iter != parsed_options.end());
+         if (serialize_) {
+                 wcf_namespace_ = iter->second;  // since there can be only 
one namespace
+         }
+
          iter = parsed_options.find("wcf");
          wcf_ = (iter != parsed_options.end());
          if (wcf_) {
@@ -142,6 +148,7 @@ class t_csharp_generator : public t_oop_
     std::ofstream f_service_;
     std::string namespace_dir_;
     bool async_ctp_;
+    bool serialize_;
     bool wcf_;
     std::string wcf_namespace_;
 };
@@ -192,7 +199,7 @@ string t_csharp_generator::csharp_type_u
        (async_ctp_ ? "using System.Threading.Tasks;\n" : "") +
     "using Thrift;\n" +
     "using Thrift.Collections;\n" +
-        (wcf_ ? "using System.ServiceModel;\n" : "") +
+    (wcf_ ? "//using System.ServiceModel;\n" : "") +
     "using System.Runtime.Serialization;\n";
 }
 
@@ -444,10 +451,10 @@ void t_csharp_generator::generate_csharp
 
   indent(out) << "#if !SILVERLIGHT" << endl;
   indent(out) << "[Serializable]" << endl; 
-  if (wcf_ &&!is_exception) {
+  indent(out) << "#endif" << endl;
+  if ((serialize_||wcf_) &&!is_exception) {
          indent(out) << "[DataContract(Namespace=\"" << wcf_namespace_ << 
"\")]" << endl; // do not make exception classes directly WCF serializable, we 
provide a seperate "fault" for that
   }
-  indent(out) << "#endif" << endl;
   bool is_final = (tstruct->annotations_.find("final") != 
tstruct->annotations_.end());
  
   indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " 
<< tstruct->get_name() << " : ";
@@ -482,11 +489,12 @@ void t_csharp_generator::generate_csharp
       indent() << "public Isset __isset;" << endl <<
       indent() << "#if !SILVERLIGHT" << endl <<
       indent() << "[Serializable]" << endl;
-      if (wcf_) {
+    out <<
+      indent() << "#endif" << endl;
+    if ((serialize_||wcf_)) {
          indent(out) << "[DataContract]" << endl;
       }
     out <<
-      indent() << "#endif" << endl <<
       indent() << "public struct Isset {" << endl;
     indent_up();
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
@@ -525,7 +533,7 @@ void t_csharp_generator::generate_csharp
   out << endl;
 
   // generate a corresponding WCF fault to wrap the exception
-  if(wcf_ && is_exception) {
+  if((serialize_||wcf_) && is_exception) {
          generate_csharp_wcffault(out, tstruct);
   }
 
@@ -539,8 +547,8 @@ void t_csharp_generator::generate_csharp
   out << endl;
   indent(out) << "#if !SILVERLIGHT" << endl;
   indent(out) << "[Serializable]" << endl;
-  indent(out) << "[DataContract]" << endl;
   indent(out) << "#endif" << endl;
+  indent(out) << "[DataContract]" << endl;
   bool is_final = (tstruct->annotations_.find("final") != 
tstruct->annotations_.end());
 
   indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " 
<< tstruct->get_name() << "Fault" << endl;
@@ -1761,7 +1769,7 @@ void t_csharp_generator::generate_proper
     generate_csharp_property(out, tfield, isPublic, generateIsset, "_");
 }
 void t_csharp_generator::generate_csharp_property(ofstream& out, t_field* 
tfield, bool isPublic, bool generateIsset, std::string fieldPrefix) {
-       if(wcf_ && isPublic) {
+       if((serialize_||wcf_) && isPublic) {
                indent(out) << "[DataMember]" << endl;
        }
     indent(out) << (isPublic ? "public " : "private ") << 
type_name(tfield->get_type())
@@ -2027,5 +2035,6 @@ std::string t_csharp_generator::get_enum
 THRIFT_REGISTER_GENERATOR(csharp, "C#",
 "    async:           Adds Async CTP support.\n"
 "    wcf:             Adds bindings for WCF to generated classes.\n"
+"    serial:          Add serialization support to generated classes.\n"
 )
 

Modified: thrift/trunk/lib/csharp/src/Collections/THashSet.cs
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/csharp/src/Collections/THashSet.cs?rev=1387715&r1=1387714&r2=1387715&view=diff
==============================================================================
--- thrift/trunk/lib/csharp/src/Collections/THashSet.cs (original)
+++ thrift/trunk/lib/csharp/src/Collections/THashSet.cs Wed Sep 19 19:30:36 2012
@@ -21,14 +21,23 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 
+#if SILVERLIGHT
+using System.Runtime.Serialization;
+#endif
+
 namespace Thrift.Collections
 {
-#if !SILVERLIGHT
-     [Serializable]
+#if SILVERLIGHT
+    [DataContract]
+#else
+       [Serializable]
 #endif
        public class THashSet<T> : ICollection<T>
        {
 #if NET_2_0 || SILVERLIGHT
+#if SILVERLIGHT
+        [DataMember]
+#endif
         TDictSet<T> set = new TDictSet<T>();
 #else
                HashSet<T> set = new HashSet<T>();
@@ -79,8 +88,14 @@ namespace Thrift.Collections
                }
 
 #if NET_2_0 || SILVERLIGHT
+#if SILVERLIGHT
+        [DataContract]
+#endif
         private class TDictSet<V> : ICollection<V>
                {
+#if SILVERLIGHT
+            [DataMember]
+#endif
                        Dictionary<V, TDictSet<V>> dict = new Dictionary<V, 
TDictSet<V>>();
 
                        public int Count


Reply via email to