THRIFT-1788 C#: Constants static constructor does not compile
authorJens Geyer <jensg@apache.org>
Tue, 18 Dec 2012 21:35:04 +0000 (22:35 +0100)
committerJens Geyer <jensg@apache.org>
Tue, 18 Dec 2012 21:35:04 +0000 (22:35 +0100)
Patch: Carl Yeksigian

compiler/cpp/src/generate/t_csharp_generator.cc

index 943445a..31e4d0b 100644 (file)
@@ -286,7 +286,7 @@ void t_csharp_generator::generate_consts(std::vector<t_const*> consts) {
   vector<t_const*>::iterator c_iter;
   bool need_static_constructor = false;
   for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
-       generate_csharp_doc(f_consts, (*c_iter));
+    generate_csharp_doc(f_consts, (*c_iter));
     if (print_const_value(f_consts, (*c_iter)->get_name(), (*c_iter)->get_type(), (*c_iter)->get_value(), false)) {
       need_static_constructor = true;
     }
@@ -309,17 +309,18 @@ void t_csharp_generator::print_const_def_value(std::ofstream& out, string name,
     const map<t_const_value*, t_const_value*>& val = value->get_map();
     map<t_const_value*, t_const_value*>::const_iterator v_iter;
     for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
-      t_type* field_type = NULL;
+      t_field* field = NULL;
       for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
         if ((*f_iter)->get_name() == v_iter->first->get_string()) {
-          field_type = (*f_iter)->get_type();
+          field = (*f_iter);
         }
       }
-      if (field_type == NULL) {
+      if (field == NULL) {
         throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
       }
+      t_type* field_type = field->get_type();
       string val = render_const_value(out, name, field_type, v_iter->second);
-      indent(out) << name << "." << v_iter->first->get_string() << " = " << val << ";" << endl;
+      indent(out) << name << "." << prop_name(field) << " = " << val << ";" << endl;
     }
   } else if (type->is_map()) {
     t_type* ktype = ((t_map*)type)->get_key_type();
@@ -367,6 +368,10 @@ void t_csharp_generator::print_const_constructor(std::ofstream& out, std::vector
 bool t_csharp_generator::print_const_value(std::ofstream& out, string name, t_type* type, t_const_value* value, bool in_static, bool defval, bool needtype) {
   indent(out);
   bool need_static_construction = !in_static;
+  while (type->is_typedef()) {
+    type = ((t_typedef*)type)->get_type();
+  }
+
   if (!defval || needtype) {
     out <<
       (in_static ? "" : "public static ") <<