THRIFT-1788 C#: Constants static constructor does not compile
Patch: Carl Yeksigian
diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc
index 943445a..31e4d0b 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -286,7 +286,7 @@
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 @@
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 @@
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 ") <<