From: Jens Geyer Date: Tue, 18 Dec 2012 21:35:04 +0000 (+0100) Subject: THRIFT-1788 C#: Constants static constructor does not compile X-Git-Tag: 0.9.1~221 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5bcf32bfa8ea52b0783a52e773b6e2546bb9f406;p=common%2Fthrift.git 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 943445a4..31e4d0b2 100644 --- a/compiler/cpp/src/generate/t_csharp_generator.cc +++ b/compiler/cpp/src/generate/t_csharp_generator.cc @@ -286,7 +286,7 @@ void t_csharp_generator::generate_consts(std::vector consts) { vector::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& val = value->get_map(); map::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 ") <<