You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 11:34:24 UTC
[32/37] thrift git commit: Revert "THRIFT-2729: C++ - .clang-format
created and applied"
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/generate/t_csharp_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc
index a0cddbf..0b9ae2a 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -43,203 +43,174 @@ using std::string;
using std::stringstream;
using std::vector;
-static const string endl = "\n"; // avoid ostream << std::endl flushes
-
-class t_csharp_generator : public t_oop_generator {
-public:
- t_csharp_generator(t_program* program,
- const std::map<std::string, std::string>& parsed_options,
- const std::string& option_string)
- : t_oop_generator(program) {
- (void)option_string;
-
- std::map<std::string, std::string>::const_iterator iter;
-
- iter = parsed_options.find("async");
- async_ = (iter != parsed_options.end());
- iter = parsed_options.find("asyncctp");
- async_ctp_ = (iter != parsed_options.end());
- if (async_ && async_ctp_) {
- throw "argument error: Cannot specify both async and asyncctp; they are incompatible.";
- }
-
- iter = parsed_options.find("nullable");
- nullable_ = (iter != parsed_options.end());
-
- iter = parsed_options.find("hashcode");
- hashcode_ = (iter != parsed_options.end());
-
- iter = parsed_options.find("union");
- union_ = (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_) {
- wcf_namespace_ = iter->second;
- }
-
- out_dir_base_ = "gen-csharp";
- }
- void init_generator();
- void close_generator();
-
- void generate_consts(std::vector<t_const*> consts);
-
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
- void generate_property(ofstream& out, t_field* tfield, bool isPublic, bool generateIsset);
- void generate_csharp_property(ofstream& out,
- t_field* tfield,
- bool isPublic,
- bool includeIsset = true,
- std::string fieldPrefix = "");
- bool print_const_value(std::ofstream& out,
- std::string name,
- t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval = false,
- bool needtype = false);
- std::string render_const_value(std::ofstream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
- void print_const_constructor(std::ofstream& out, std::vector<t_const*> consts);
- void print_const_def_value(std::ofstream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
-
- void generate_csharp_struct(t_struct* tstruct, bool is_exception);
- void generate_csharp_union(t_struct* tunion);
- void generate_csharp_struct_definition(std::ofstream& out,
- t_struct* tstruct,
- bool is_xception = false,
- bool in_class = false,
- bool is_result = false);
- void generate_csharp_union_definition(std::ofstream& out, t_struct* tunion);
- void generate_csharp_union_class(std::ofstream& out, t_struct* tunion, t_field* tfield);
- void generate_csharp_wcffault(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_reader(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_result_writer(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_writer(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_tostring(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_equals(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_struct_hashcode(std::ofstream& out, t_struct* tstruct);
- void generate_csharp_union_reader(std::ofstream& out, t_struct* tunion);
-
- void generate_function_helpers(t_function* tfunction);
- void generate_service_interface(t_service* tservice);
- void generate_service_helpers(t_service* tservice);
- void generate_service_client(t_service* tservice);
- void generate_service_server(t_service* tservice);
- void generate_process_function(t_service* tservice, t_function* function);
-
- void generate_deserialize_field(std::ofstream& out,
- t_field* tfield,
- std::string prefix = "",
- bool is_propertyless = false);
- void generate_deserialize_struct(std::ofstream& out, t_struct* tstruct, std::string prefix = "");
- void generate_deserialize_container(std::ofstream& out, t_type* ttype, std::string prefix = "");
- void generate_deserialize_set_element(std::ofstream& out, t_set* tset, std::string prefix = "");
- void generate_deserialize_map_element(std::ofstream& out, t_map* tmap, std::string prefix = "");
- void generate_deserialize_list_element(std::ofstream& out, t_list* list, std::string prefix = "");
- void generate_serialize_field(std::ofstream& out,
- t_field* tfield,
- std::string prefix = "",
- bool is_element = false,
- bool is_propertyless = false);
- void generate_serialize_struct(std::ofstream& out, t_struct* tstruct, std::string prefix = "");
- void generate_serialize_container(std::ofstream& out, t_type* ttype, std::string prefix = "");
- void generate_serialize_map_element(std::ofstream& out,
- t_map* tmap,
- std::string iter,
- std::string map);
- void generate_serialize_set_element(std::ofstream& out, t_set* tmap, std::string iter);
- void generate_serialize_list_element(std::ofstream& out, t_list* tlist, std::string iter);
-
- void generate_csharp_doc(std::ofstream& out, t_field* field);
- void generate_csharp_doc(std::ofstream& out, t_doc* tdoc);
- void generate_csharp_doc(std::ofstream& out, t_function* tdoc);
- void generate_csharp_docstring_comment(std::ofstream& out, string contents);
-
- void start_csharp_namespace(std::ofstream& out);
- void end_csharp_namespace(std::ofstream& out);
-
- std::string csharp_type_usings();
- std::string csharp_thrift_usings();
-
- std::string type_name(t_type* ttype,
- bool in_countainer = false,
- bool in_init = false,
- bool in_param = false,
- bool is_required = false);
- std::string base_type_name(t_base_type* tbase,
- bool in_container = false,
- bool in_param = false,
- bool is_required = false);
- std::string declare_field(t_field* tfield, bool init = false, std::string prefix = "");
- std::string function_signature_async_begin(t_function* tfunction, std::string prefix = "");
- std::string function_signature_async_end(t_function* tfunction, std::string prefix = "");
- std::string function_signature_async(t_function* tfunction, std::string prefix = "");
- std::string function_signature(t_function* tfunction, std::string prefix = "");
- std::string argument_list(t_struct* tstruct);
- std::string type_to_enum(t_type* ttype);
- std::string prop_name(t_field* tfield, bool suppress_mapping = false);
- std::string get_enum_class_name(t_type* type);
-
- bool field_has_default(t_field* tfield) { return tfield->get_value() != NULL; }
-
- bool field_is_required(t_field* tfield) { return tfield->get_req() == t_field::T_REQUIRED; }
-
- bool type_can_be_null(t_type* ttype) {
- while (ttype->is_typedef()) {
- ttype = ((t_typedef*)ttype)->get_type();
- }
+static const string endl = "\n"; // avoid ostream << std::endl flushes
+
+class t_csharp_generator : public t_oop_generator
+{
+ public:
+ t_csharp_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_oop_generator(program)
+ {
+ (void) option_string;
+
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("async");
+ async_ = (iter != parsed_options.end());
+ iter = parsed_options.find("asyncctp");
+ async_ctp_ = (iter != parsed_options.end());
+ if (async_ && async_ctp_) {
+ throw "argument error: Cannot specify both async and asyncctp; they are incompatible.";
+ }
+
+ iter = parsed_options.find("nullable");
+ nullable_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("hashcode");
+ hashcode_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("union");
+ union_ = (iter != parsed_options.end());
- return ttype->is_container() || ttype->is_struct() || ttype->is_xception()
- || ttype->is_string();
- }
-
-private:
- std::string namespace_name_;
- std::ofstream f_service_;
- std::string namespace_dir_;
- bool async_;
- bool async_ctp_;
- bool nullable_;
- bool union_;
- bool hashcode_;
- bool serialize_;
- bool wcf_;
- std::string wcf_namespace_;
-
- std::map<std::string, int> csharp_keywords;
-
- void* member_mapping_scope;
- std::map<std::string, std::string> member_name_mapping;
-
- void init_keywords();
- std::string normalize_name(std::string name);
- std::string make_valid_csharp_identifier(std::string const& fromName);
- void prepare_member_name_mapping(t_struct* tstruct);
- void prepare_member_name_mapping(void* scope,
- const vector<t_field*>& members,
- const string& structname);
- void cleanup_member_name_mapping(void* scope);
- string get_mapped_member_name(string oldname);
+ 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_) {
+ wcf_namespace_ = iter->second;
+ }
+
+ out_dir_base_ = "gen-csharp";
+ }
+ void init_generator();
+ void close_generator();
+
+ void generate_consts(std::vector<t_const*> consts);
+
+ void generate_typedef (t_typedef* ttypedef);
+ void generate_enum (t_enum* tenum);
+ void generate_struct (t_struct* tstruct);
+ void generate_union (t_struct* tunion);
+ void generate_xception (t_struct* txception);
+ void generate_service (t_service* tservice);
+ void generate_property(ofstream& out, t_field* tfield, bool isPublic, bool generateIsset);
+ void generate_csharp_property(ofstream& out, t_field* tfield, bool isPublic, bool includeIsset=true, std::string fieldPrefix = "");
+ bool print_const_value (std::ofstream& out, std::string name, t_type* type, t_const_value* value, bool in_static, bool defval=false, bool needtype=false);
+ std::string render_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value);
+ void print_const_constructor(std::ofstream& out, std::vector<t_const*> consts);
+ void print_const_def_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value);
+
+ void generate_csharp_struct(t_struct* tstruct, bool is_exception);
+ void generate_csharp_union(t_struct* tunion);
+ void generate_csharp_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool in_class=false, bool is_result=false);
+ void generate_csharp_union_definition(std::ofstream& out, t_struct* tunion);
+ void generate_csharp_union_class(std::ofstream& out, t_struct* tunion, t_field* tfield);
+ void generate_csharp_wcffault(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_reader(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_result_writer(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_writer(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_tostring(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_equals(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_struct_hashcode(std::ofstream& out, t_struct* tstruct);
+ void generate_csharp_union_reader(std::ofstream& out, t_struct* tunion);
+
+ void generate_function_helpers(t_function* tfunction);
+ void generate_service_interface (t_service* tservice);
+ void generate_service_helpers (t_service* tservice);
+ void generate_service_client (t_service* tservice);
+ void generate_service_server (t_service* tservice);
+ void generate_process_function (t_service* tservice, t_function* function);
+
+ void generate_deserialize_field (std::ofstream& out, t_field* tfield, std::string prefix="", bool is_propertyless=false);
+ void generate_deserialize_struct (std::ofstream& out, t_struct* tstruct, std::string prefix="");
+ void generate_deserialize_container (std::ofstream& out, t_type* ttype, std::string prefix="");
+ void generate_deserialize_set_element (std::ofstream& out, t_set* tset, std::string prefix="");
+ void generate_deserialize_map_element (std::ofstream& out, t_map* tmap, std::string prefix="");
+ void generate_deserialize_list_element (std::ofstream& out, t_list* list, std::string prefix="");
+ void generate_serialize_field (std::ofstream& out, t_field* tfield, std::string prefix="", bool is_element=false, bool is_propertyless=false);
+ void generate_serialize_struct (std::ofstream& out, t_struct* tstruct, std::string prefix="");
+ void generate_serialize_container (std::ofstream& out, t_type* ttype, std::string prefix="");
+ void generate_serialize_map_element (std::ofstream& out, t_map* tmap, std::string iter, std::string map);
+ void generate_serialize_set_element (std::ofstream& out, t_set* tmap, std::string iter);
+ void generate_serialize_list_element (std::ofstream& out, t_list* tlist, std::string iter);
+
+ void generate_csharp_doc (std::ofstream& out, t_field* field);
+ void generate_csharp_doc (std::ofstream& out, t_doc* tdoc);
+ void generate_csharp_doc (std::ofstream& out, t_function* tdoc);
+ void generate_csharp_docstring_comment (std::ofstream &out, string contents);
+
+ void start_csharp_namespace (std::ofstream& out);
+ void end_csharp_namespace (std::ofstream& out);
+
+ std::string csharp_type_usings();
+ std::string csharp_thrift_usings();
+
+ std::string type_name(t_type* ttype, bool in_countainer=false, bool in_init=false, bool in_param=false, bool is_required=false);
+ std::string base_type_name(t_base_type* tbase, bool in_container=false, bool in_param=false, bool is_required=false);
+ std::string declare_field(t_field* tfield, bool init=false, std::string prefix="");
+ std::string function_signature_async_begin(t_function* tfunction, std::string prefix = "");
+ std::string function_signature_async_end(t_function* tfunction, std::string prefix = "");
+ std::string function_signature_async(t_function* tfunction, std::string prefix = "");
+ std::string function_signature(t_function* tfunction, std::string prefix="");
+ std::string argument_list(t_struct* tstruct);
+ std::string type_to_enum(t_type* ttype);
+ std::string prop_name(t_field* tfield, bool suppress_mapping = false);
+ std::string get_enum_class_name(t_type* type);
+
+ bool field_has_default(t_field* tfield) {
+ return tfield->get_value() != NULL;
+ }
+
+ bool field_is_required(t_field* tfield) {
+ return tfield->get_req() == t_field::T_REQUIRED;
+ }
+
+ bool type_can_be_null(t_type* ttype) {
+ while (ttype->is_typedef()) {
+ ttype = ((t_typedef*)ttype)->get_type();
+ }
+
+ return ttype->is_container() ||
+ ttype->is_struct() ||
+ ttype->is_xception() ||
+ ttype->is_string();
+ }
+
+ private:
+ std::string namespace_name_;
+ std::ofstream f_service_;
+ std::string namespace_dir_;
+ bool async_;
+ bool async_ctp_;
+ bool nullable_;
+ bool union_;
+ bool hashcode_;
+ bool serialize_;
+ bool wcf_;
+ std::string wcf_namespace_;
+
+ std::map<std::string, int> csharp_keywords;
+
+ void* member_mapping_scope;
+ std::map<std::string, std::string> member_name_mapping;
+
+ void init_keywords();
+ std::string normalize_name( std::string name);
+ std::string make_valid_csharp_identifier( std::string const & fromName);
+ void prepare_member_name_mapping( t_struct* tstruct);
+ void prepare_member_name_mapping( void* scope, const vector<t_field*>& members, const string & structname);
+ void cleanup_member_name_mapping( void* scope);
+ string get_mapped_member_name( string oldname);
};
+
void t_csharp_generator::init_generator() {
MKDIR(get_out_dir().c_str());
namespace_name_ = program_->get_namespace("csharp");
@@ -272,12 +243,12 @@ void t_csharp_generator::init_generator() {
pverbose("- wcf ........ %s\n", (wcf_ ? "ON" : "off"));
}
-std::string t_csharp_generator::normalize_name(std::string name) {
- string tmp(name);
+std::string t_csharp_generator::normalize_name( std::string name) {
+ string tmp( name );
std::transform(tmp.begin(), tmp.end(), tmp.begin(), static_cast<int (*)(int)>(std::tolower));
// un-conflict keywords by prefixing with "@"
- if (csharp_keywords.find(tmp) != csharp_keywords.end()) {
+ if ( csharp_keywords.find(tmp) != csharp_keywords.end()) {
return "@" + name;
}
@@ -290,112 +261,113 @@ void t_csharp_generator::init_keywords() {
// C# keywords
csharp_keywords["abstract"] = 1;
- csharp_keywords["as"] = 1;
- csharp_keywords["base"] = 1;
- csharp_keywords["bool"] = 1;
- csharp_keywords["break"] = 1;
- csharp_keywords["byte"] = 1;
- csharp_keywords["case"] = 1;
- csharp_keywords["catch"] = 1;
- csharp_keywords["char"] = 1;
- csharp_keywords["checked"] = 1;
- csharp_keywords["class"] = 1;
- csharp_keywords["const"] = 1;
- csharp_keywords["continue"] = 1;
- csharp_keywords["decimal"] = 1;
- csharp_keywords["default"] = 1;
- csharp_keywords["delegate"] = 1;
- csharp_keywords["do"] = 1;
- csharp_keywords["double"] = 1;
- csharp_keywords["else"] = 1;
- csharp_keywords["enum"] = 1;
- csharp_keywords["event"] = 1;
- csharp_keywords["explicit"] = 1;
- csharp_keywords["extern"] = 1;
- csharp_keywords["false"] = 1;
- csharp_keywords["finally"] = 1;
- csharp_keywords["fixed"] = 1;
- csharp_keywords["float"] = 1;
- csharp_keywords["for"] = 1;
- csharp_keywords["foreach"] = 1;
- csharp_keywords["goto"] = 1;
- csharp_keywords["if"] = 1;
- csharp_keywords["implicit"] = 1;
- csharp_keywords["in"] = 1;
- csharp_keywords["int"] = 1;
- csharp_keywords["interface"] = 1;
- csharp_keywords["internal"] = 1;
- csharp_keywords["is"] = 1;
- csharp_keywords["lock"] = 1;
- csharp_keywords["long"] = 1;
- csharp_keywords["namespace"] = 1;
- csharp_keywords["new"] = 1;
- csharp_keywords["null"] = 1;
- csharp_keywords["object"] = 1;
- csharp_keywords["operator"] = 1;
- csharp_keywords["out"] = 1;
- csharp_keywords["override"] = 1;
- csharp_keywords["params"] = 1;
- csharp_keywords["private"] = 1;
- csharp_keywords["protected"] = 1;
- csharp_keywords["public"] = 1;
- csharp_keywords["readonly"] = 1;
- csharp_keywords["ref"] = 1;
- csharp_keywords["return"] = 1;
- csharp_keywords["sbyte"] = 1;
- csharp_keywords["sealed"] = 1;
- csharp_keywords["short"] = 1;
- csharp_keywords["sizeof"] = 1;
- csharp_keywords["stackalloc"] = 1;
- csharp_keywords["static"] = 1;
- csharp_keywords["string"] = 1;
- csharp_keywords["struct"] = 1;
- csharp_keywords["switch"] = 1;
- csharp_keywords["this"] = 1;
- csharp_keywords["throw"] = 1;
- csharp_keywords["true"] = 1;
- csharp_keywords["try"] = 1;
- csharp_keywords["typeof"] = 1;
- csharp_keywords["uint"] = 1;
- csharp_keywords["ulong"] = 1;
- csharp_keywords["unchecked"] = 1;
- csharp_keywords["unsafe"] = 1;
- csharp_keywords["ushort"] = 1;
- csharp_keywords["using"] = 1;
- csharp_keywords["virtual"] = 1;
- csharp_keywords["void"] = 1;
- csharp_keywords["volatile"] = 1;
- csharp_keywords["while"] = 1;
+ csharp_keywords["as"]= 1;
+ csharp_keywords["base"]= 1;
+ csharp_keywords["bool"]= 1;
+ csharp_keywords["break"]= 1;
+ csharp_keywords["byte"]= 1;
+ csharp_keywords["case"]= 1;
+ csharp_keywords["catch"]= 1;
+ csharp_keywords["char"]= 1;
+ csharp_keywords["checked"]= 1;
+ csharp_keywords["class"]= 1;
+ csharp_keywords["const"]= 1;
+ csharp_keywords["continue"]= 1;
+ csharp_keywords["decimal"]= 1;
+ csharp_keywords["default"]= 1;
+ csharp_keywords["delegate"]= 1;
+ csharp_keywords["do"]= 1;
+ csharp_keywords["double"]= 1;
+ csharp_keywords["else"]= 1;
+ csharp_keywords["enum"]= 1;
+ csharp_keywords["event"]= 1;
+ csharp_keywords["explicit"]= 1;
+ csharp_keywords["extern"]= 1;
+ csharp_keywords["false"]= 1;
+ csharp_keywords["finally"]= 1;
+ csharp_keywords["fixed"]= 1;
+ csharp_keywords["float"]= 1;
+ csharp_keywords["for"]= 1;
+ csharp_keywords["foreach"]= 1;
+ csharp_keywords["goto"]= 1;
+ csharp_keywords["if"]= 1;
+ csharp_keywords["implicit"]= 1;
+ csharp_keywords["in"]= 1;
+ csharp_keywords["int"]= 1;
+ csharp_keywords["interface"]= 1;
+ csharp_keywords["internal"]= 1;
+ csharp_keywords["is"]= 1;
+ csharp_keywords["lock"]= 1;
+ csharp_keywords["long"]= 1;
+ csharp_keywords["namespace"]= 1;
+ csharp_keywords["new"]= 1;
+ csharp_keywords["null"]= 1;
+ csharp_keywords["object"]= 1;
+ csharp_keywords["operator"]= 1;
+ csharp_keywords["out"]= 1;
+ csharp_keywords["override"]= 1;
+ csharp_keywords["params"]= 1;
+ csharp_keywords["private"]= 1;
+ csharp_keywords["protected"]= 1;
+ csharp_keywords["public"]= 1;
+ csharp_keywords["readonly"]= 1;
+ csharp_keywords["ref"]= 1;
+ csharp_keywords["return"]= 1;
+ csharp_keywords["sbyte"]= 1;
+ csharp_keywords["sealed"]= 1;
+ csharp_keywords["short"]= 1;
+ csharp_keywords["sizeof"]= 1;
+ csharp_keywords["stackalloc"]= 1;
+ csharp_keywords["static"]= 1;
+ csharp_keywords["string"]= 1;
+ csharp_keywords["struct"]= 1;
+ csharp_keywords["switch"]= 1;
+ csharp_keywords["this"]= 1;
+ csharp_keywords["throw"]= 1;
+ csharp_keywords["true"]= 1;
+ csharp_keywords["try"]= 1;
+ csharp_keywords["typeof"]= 1;
+ csharp_keywords["uint"]= 1;
+ csharp_keywords["ulong"]= 1;
+ csharp_keywords["unchecked"]= 1;
+ csharp_keywords["unsafe"]= 1;
+ csharp_keywords["ushort"]= 1;
+ csharp_keywords["using"]= 1;
+ csharp_keywords["virtual"]= 1;
+ csharp_keywords["void"]= 1;
+ csharp_keywords["volatile"]= 1;
+ csharp_keywords["while"]= 1;
// C# contextual keywords
- csharp_keywords["add"] = 1;
- csharp_keywords["alias"] = 1;
- csharp_keywords["ascending"] = 1;
- csharp_keywords["async"] = 1;
- csharp_keywords["await"] = 1;
- csharp_keywords["descending"] = 1;
- csharp_keywords["dynamic"] = 1;
- csharp_keywords["from"] = 1;
- csharp_keywords["get"] = 1;
- csharp_keywords["global"] = 1;
- csharp_keywords["group"] = 1;
- csharp_keywords["into"] = 1;
- csharp_keywords["join"] = 1;
- csharp_keywords["let"] = 1;
- csharp_keywords["orderby"] = 1;
- csharp_keywords["partial"] = 1;
- csharp_keywords["remove"] = 1;
- csharp_keywords["select"] = 1;
- csharp_keywords["set"] = 1;
- csharp_keywords["value"] = 1;
- csharp_keywords["var"] = 1;
- csharp_keywords["where"] = 1;
- csharp_keywords["yield"] = 1;
+ csharp_keywords["add"]= 1;
+ csharp_keywords["alias"]= 1;
+ csharp_keywords["ascending"]= 1;
+ csharp_keywords["async"]= 1;
+ csharp_keywords["await"]= 1;
+ csharp_keywords["descending"]= 1;
+ csharp_keywords["dynamic"]= 1;
+ csharp_keywords["from"]= 1;
+ csharp_keywords["get"]= 1;
+ csharp_keywords["global"]= 1;
+ csharp_keywords["group"]= 1;
+ csharp_keywords["into"]= 1;
+ csharp_keywords["join"]= 1;
+ csharp_keywords["let"]= 1;
+ csharp_keywords["orderby"]= 1;
+ csharp_keywords["partial"]= 1;
+ csharp_keywords["remove"]= 1;
+ csharp_keywords["select"]= 1;
+ csharp_keywords["set"]= 1;
+ csharp_keywords["value"]= 1;
+ csharp_keywords["var"]= 1;
+ csharp_keywords["where"]= 1;
+ csharp_keywords["yield"]= 1;
}
void t_csharp_generator::start_csharp_namespace(ofstream& out) {
if (!namespace_name_.empty()) {
- out << "namespace " << namespace_name_ << "\n";
+ out <<
+ "namespace " << namespace_name_ << "\n";
scope_up(out);
}
}
@@ -407,43 +379,53 @@ void t_csharp_generator::end_csharp_namespace(ofstream& out) {
}
string t_csharp_generator::csharp_type_usings() {
- return string() + "using System;\n" + "using System.Collections;\n"
- + "using System.Collections.Generic;\n" + "using System.Text;\n" + "using System.IO;\n"
- + ((async_ || async_ctp_) ? "using System.Threading.Tasks;\n" : "") + "using Thrift;\n"
- + "using Thrift.Collections;\n" + ((serialize_ || wcf_) ? "#if !SILVERLIGHT\n" : "")
- + ((serialize_ || wcf_) ? "using System.Xml.Serialization;\n" : "")
- + ((serialize_ || wcf_) ? "#endif\n" : "") + (wcf_ ? "//using System.ServiceModel;\n" : "")
- + "using System.Runtime.Serialization;\n";
+ return string() +
+ "using System;\n" +
+ "using System.Collections;\n" +
+ "using System.Collections.Generic;\n" +
+ "using System.Text;\n" +
+ "using System.IO;\n" +
+ ((async_||async_ctp_) ? "using System.Threading.Tasks;\n" : "") +
+ "using Thrift;\n" +
+ "using Thrift.Collections;\n" +
+ ((serialize_||wcf_) ? "#if !SILVERLIGHT\n" : "") +
+ ((serialize_||wcf_) ? "using System.Xml.Serialization;\n" : "") +
+ ((serialize_||wcf_) ? "#endif\n" : "") +
+ (wcf_ ? "//using System.ServiceModel;\n" : "") +
+ "using System.Runtime.Serialization;\n";
}
string t_csharp_generator::csharp_thrift_usings() {
- return string() + "using Thrift.Protocol;\n" + "using Thrift.Transport;\n";
+ return string() +
+ "using Thrift.Protocol;\n" +
+ "using Thrift.Transport;\n";
}
-void t_csharp_generator::close_generator() {
-}
+void t_csharp_generator::close_generator() { }
void t_csharp_generator::generate_typedef(t_typedef* ttypedef) {
- (void)ttypedef;
+ (void) ttypedef;
}
void t_csharp_generator::generate_enum(t_enum* tenum) {
- string f_enum_name = namespace_dir_ + "/" + (tenum->get_name()) + ".cs";
+ string f_enum_name = namespace_dir_+"/" + (tenum->get_name())+".cs";
ofstream f_enum;
f_enum.open(f_enum_name.c_str());
- f_enum << autogen_comment() << endl;
+ f_enum <<
+ autogen_comment() << endl;
start_csharp_namespace(f_enum);
generate_csharp_doc(f_enum, tenum);
- indent(f_enum) << "public enum " << tenum->get_name() << "\n";
+ indent(f_enum) <<
+ "public enum " << tenum->get_name() << "\n";
scope_up(f_enum);
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- generate_csharp_doc(f_enum, *c_iter);
+ generate_csharp_doc(f_enum, *c_iter);
int value = (*c_iter)->get_value();
indent(f_enum) << (*c_iter)->get_name() << " = " << value << "," << endl;
@@ -457,30 +439,28 @@ void t_csharp_generator::generate_enum(t_enum* tenum) {
}
void t_csharp_generator::generate_consts(std::vector<t_const*> consts) {
- if (consts.empty()) {
+ if (consts.empty()){
return;
}
- string f_consts_name = namespace_dir_ + '/' + program_name_ + ".Constants.cs";
+ string f_consts_name = namespace_dir_ + '/' + program_name_ + ".Constants.cs";
ofstream f_consts;
f_consts.open(f_consts_name.c_str());
- f_consts << autogen_comment() << csharp_type_usings() << endl;
+ f_consts <<
+ autogen_comment() <<
+ csharp_type_usings() << endl;
start_csharp_namespace(f_consts);
- indent(f_consts) << "public static class " << make_valid_csharp_identifier(program_name_)
- << "Constants" << endl;
+ indent(f_consts) <<
+ "public static class " << make_valid_csharp_identifier(program_name_) << "Constants" << endl;
scope_up(f_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));
- if (print_const_value(f_consts,
- (*c_iter)->get_name(),
- (*c_iter)->get_type(),
- (*c_iter)->get_value(),
- false)) {
+ if (print_const_value(f_consts, (*c_iter)->get_name(), (*c_iter)->get_type(), (*c_iter)->get_value(), false)) {
need_static_constructor = true;
}
}
@@ -494,10 +474,8 @@ void t_csharp_generator::generate_consts(std::vector<t_const*> consts) {
f_consts.close();
}
-void t_csharp_generator::print_const_def_value(std::ofstream& out,
- string name,
- t_type* type,
- t_const_value* value) {
+void t_csharp_generator::print_const_def_value(std::ofstream& out, string name, t_type* type, t_const_value* value)
+{
if (type->is_struct() || type->is_xception()) {
const vector<t_field*>& fields = ((t_struct*)type)->get_members();
vector<t_field*>::const_iterator f_iter;
@@ -525,8 +503,7 @@ void t_csharp_generator::print_const_def_value(std::ofstream& out,
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
string key = render_const_value(out, name, ktype, v_iter->first);
string val = render_const_value(out, name, vtype, v_iter->second);
- indent(out) << name << "[" << key << "]"
- << " = " << val << ";" << endl;
+ indent(out) << name << "[" << key << "]" << " = " << val << ";" << endl;
}
} else if (type->is_list() || type->is_set()) {
t_type* etype;
@@ -546,8 +523,7 @@ void t_csharp_generator::print_const_def_value(std::ofstream& out,
}
void t_csharp_generator::print_const_constructor(std::ofstream& out, std::vector<t_const*> consts) {
- indent(out) << "static " << make_valid_csharp_identifier(program_name_).c_str() << "Constants()"
- << endl;
+ indent(out) << "static " << make_valid_csharp_identifier(program_name_).c_str() << "Constants()" << endl;
scope_up(out);
vector<t_const*>::iterator c_iter;
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
@@ -560,15 +536,9 @@ void t_csharp_generator::print_const_constructor(std::ofstream& out, std::vector
scope_down(out);
}
-// it seems like all that methods that call this are using in_static to be the opposite of what it
-// would imply
-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) {
+
+//it seems like all that methods that call this are using in_static to be the opposite of what it would imply
+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()) {
@@ -576,16 +546,16 @@ bool t_csharp_generator::print_const_value(std::ofstream& out,
}
if (!defval || needtype) {
- out << (in_static ? "" : type->is_base_type() ? "public const " : "public static ")
- << type_name(type) << " ";
+ out <<
+ (in_static ? "" : type->is_base_type() ? "public const " : "public static ") <<
+ type_name(type) << " ";
}
if (type->is_base_type()) {
string v2 = render_const_value(out, name, type, value);
out << name << " = " << v2 << ";" << endl;
need_static_construction = false;
} else if (type->is_enum()) {
- out << name << " = " << type_name(type, false, true) << "." << value->get_identifier_name()
- << ";" << endl;
+ out << name << " = " << type_name(type, false, true) << "." << value->get_identifier_name() << ";" << endl;
need_static_construction = false;
} else if (type->is_struct() || type->is_xception()) {
out << name << " = new " << type_name(type) << "();" << endl;
@@ -602,37 +572,34 @@ bool t_csharp_generator::print_const_value(std::ofstream& out,
return need_static_construction;
}
-std::string t_csharp_generator::render_const_value(ofstream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)name;
+std::string t_csharp_generator::render_const_value(ofstream& out, string name, t_type* type, t_const_value* value) {
+ (void) name;
std::ostringstream render;
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
- case t_base_type::TYPE_STRING:
- render << '"' << get_escaped_string(value) << '"';
- break;
- case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "true" : "false");
- break;
- case t_base_type::TYPE_BYTE:
- case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
- case t_base_type::TYPE_I64:
- render << value->get_integer();
- break;
- case t_base_type::TYPE_DOUBLE:
- if (value->get_type() == t_const_value::CV_INTEGER) {
+ case t_base_type::TYPE_STRING:
+ render << '"' << get_escaped_string(value) << '"';
+ break;
+ case t_base_type::TYPE_BOOL:
+ render << ((value->get_integer() > 0) ? "true" : "false");
+ break;
+ case t_base_type::TYPE_BYTE:
+ case t_base_type::TYPE_I16:
+ case t_base_type::TYPE_I32:
+ case t_base_type::TYPE_I64:
render << value->get_integer();
- } else {
- render << value->get_double();
- }
- break;
- default:
- throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
+ break;
+ case t_base_type::TYPE_DOUBLE:
+ if (value->get_type() == t_const_value::CV_INTEGER) {
+ render << value->get_integer();
+ } else {
+ render << value->get_double();
+ }
+ break;
+ default:
+ throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
}
} else if (type->is_enum()) {
render << type->get_name() << "." << value->get_identifier_name();
@@ -663,18 +630,17 @@ void t_csharp_generator::generate_csharp_struct(t_struct* tstruct, bool is_excep
f_struct.open(f_struct_name.c_str());
- f_struct << autogen_comment() << csharp_type_usings() << csharp_thrift_usings() << endl;
+ f_struct <<
+ autogen_comment() <<
+ csharp_type_usings() <<
+ csharp_thrift_usings() << endl;
generate_csharp_struct_definition(f_struct, tstruct, is_exception);
f_struct.close();
}
-void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
- t_struct* tstruct,
- bool is_exception,
- bool in_class,
- bool is_result) {
+void t_csharp_generator::generate_csharp_struct_definition(ofstream &out, t_struct* tstruct, bool is_exception, bool in_class, bool is_result) {
if (!in_class) {
start_csharp_namespace(out);
@@ -683,20 +649,17 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
out << endl;
generate_csharp_doc(out, tstruct);
- prepare_member_name_mapping(tstruct);
+ prepare_member_name_mapping( tstruct);
indent(out) << "#if !SILVERLIGHT" << endl;
indent(out) << "[Serializable]" << endl;
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
+ 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
}
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
- indent(out) << "public " << (is_final ? "sealed " : "") << "partial class "
- << normalize_name(tstruct->get_name()) << " : ";
+ indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " << normalize_name(tstruct->get_name()) << " : ";
if (is_exception) {
out << "TException, ";
@@ -710,7 +673,7 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
- // make private members with public Properties
+ //make private members with public Properties
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
// if the field is requied, then we use auto-properties
if (!field_is_required((*m_iter)) && (!nullable_ || field_has_default((*m_iter)))) {
@@ -737,18 +700,23 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
}
}
- bool generate_isset = (nullable_ && has_non_required_default_value_fields)
- || (!nullable_ && has_non_required_fields);
+ bool generate_isset =
+ (nullable_ && has_non_required_default_value_fields)
+ || (!nullable_ && has_non_required_fields);
if (generate_isset) {
- out << endl;
- if (serialize_ || wcf_) {
- out << indent() << "[XmlIgnore] // XmlSerializer" << endl << indent()
- << "[DataMember(Order = 1)] // XmlObjectSerializer, DataContractJsonSerializer, etc."
- << endl;
- }
- out << indent() << "public Isset __isset;" << endl << indent() << "#if !SILVERLIGHT" << endl
- << indent() << "[Serializable]" << endl << indent() << "#endif" << endl;
- if (serialize_ || wcf_) {
+ out <<
+ endl;
+ if(serialize_||wcf_) {
+ out <<
+ indent() << "[XmlIgnore] // XmlSerializer" << endl <<
+ indent() << "[DataMember(Order = 1)] // XmlObjectSerializer, DataContractJsonSerializer, etc." << endl;
+ }
+ out <<
+ indent() << "public Isset __isset;" << endl <<
+ indent() << "#if !SILVERLIGHT" << endl <<
+ indent() << "[Serializable]" << endl <<
+ indent() << "#endif" << endl;
+ if (serialize_||wcf_) {
indent(out) << "[DataContract]" << endl;
}
indent(out) << "public struct Isset {" << endl;
@@ -760,7 +728,7 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
// if it is not required, if it has a default value, we need to generate Isset
// if we are not nullable, then we generate Isset
if (!is_required && (!nullable_ || has_default)) {
- if (serialize_ || wcf_) {
+ if(serialize_||wcf_) {
indent(out) << "[DataMember]" << endl;
}
indent(out) << "public bool " << normalize_name((*m_iter)->get_name()) << ";" << endl;
@@ -770,7 +738,7 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
indent_down();
indent(out) << "}" << endl << endl;
- if (generate_isset && (serialize_ || wcf_)) {
+ if(generate_isset && (serialize_||wcf_)) {
indent(out) << "#region XmlSerializer support" << endl << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
@@ -806,15 +774,9 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
if (field_is_required((*m_iter))) {
print_const_value(out, "this." + prop_name(*m_iter), t, (*m_iter)->get_value(), true, true);
} else {
- print_const_value(out,
- "this._" + (*m_iter)->get_name(),
- t,
- (*m_iter)->get_value(),
- true,
- true);
+ print_const_value(out, "this._" + (*m_iter)->get_name(), t, (*m_iter)->get_value(), true, true);
// Optionals with defaults are marked set
- indent(out) << "this.__isset." << normalize_name((*m_iter)->get_name()) << " = true;"
- << endl;
+ indent(out) << "this.__isset." << normalize_name((*m_iter)->get_name()) << " = true;" << endl;
}
}
}
@@ -839,8 +801,7 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if (field_is_required((*m_iter))) {
- indent(out) << "this." << prop_name((*m_iter)) << " = " << (*m_iter)->get_name() << ";"
- << endl;
+ indent(out) << "this." << prop_name((*m_iter)) << " = " << (*m_iter)->get_name() << ";" << endl;
}
}
@@ -863,11 +824,11 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream& out,
out << endl;
// generate a corresponding WCF fault to wrap the exception
- if ((serialize_ || wcf_) && is_exception) {
+ if((serialize_||wcf_) && is_exception) {
generate_csharp_wcffault(out, tstruct);
}
- cleanup_member_name_mapping(tstruct);
+ cleanup_member_name_mapping( tstruct);
if (!in_class) {
end_csharp_namespace(out);
}
@@ -881,8 +842,7 @@ void t_csharp_generator::generate_csharp_wcffault(ofstream& out, t_struct* tstru
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;
+ indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " << tstruct->get_name() << "Fault" << endl;
scope_up(out);
@@ -891,7 +851,8 @@ void t_csharp_generator::generate_csharp_wcffault(ofstream& out, t_struct* tstru
// make private members with public Properties
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- indent(out) << "private " << declare_field(*m_iter, false, "_") << endl;
+ indent(out) <<
+ "private " << declare_field(*m_iter, false, "_") << endl;
}
out << endl;
@@ -904,7 +865,8 @@ void t_csharp_generator::generate_csharp_wcffault(ofstream& out, t_struct* tstru
}
void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct* tstruct) {
- indent(out) << "public void Read (TProtocol iprot)" << endl;
+ indent(out) <<
+ "public void Read (TProtocol iprot)" << endl;
scope_up(out);
const vector<t_field*>& fields = tstruct->get_members();
@@ -917,28 +879,38 @@ void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct*
}
}
- indent(out) << "TField field;" << endl << indent() << "iprot.ReadStructBegin();" << endl;
+ indent(out) <<
+ "TField field;" << endl <<
+ indent() << "iprot.ReadStructBegin();" << endl;
- indent(out) << "while (true)" << endl;
+ indent(out) <<
+ "while (true)" << endl;
scope_up(out);
- indent(out) << "field = iprot.ReadFieldBegin();" << endl;
+ indent(out) <<
+ "field = iprot.ReadFieldBegin();" << endl;
- indent(out) << "if (field.Type == TType.Stop) { " << endl;
+ indent(out) <<
+ "if (field.Type == TType.Stop) { " << endl;
indent_up();
- indent(out) << "break;" << endl;
+ indent(out) <<
+ "break;" << endl;
indent_down();
- indent(out) << "}" << endl;
+ indent(out) <<
+ "}" << endl;
- indent(out) << "switch (field.ID)" << endl;
+ indent(out) <<
+ "switch (field.ID)" << endl;
scope_up(out);
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
bool is_required = field_is_required((*f_iter));
- indent(out) << "case " << (*f_iter)->get_key() << ":" << endl;
+ indent(out) <<
+ "case " << (*f_iter)->get_key() << ":" << endl;
indent_up();
- indent(out) << "if (field.Type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
+ indent(out) <<
+ "if (field.Type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
indent_up();
generate_deserialize_field(out, *f_iter);
@@ -947,12 +919,16 @@ void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct*
}
indent_down();
- out << indent() << "} else { " << endl << indent() << " TProtocolUtil.Skip(iprot, field.Type);"
- << endl << indent() << "}" << endl << indent() << "break;" << endl;
+ out <<
+ indent() << "} else { " << endl <<
+ indent() << " TProtocolUtil.Skip(iprot, field.Type);" << endl <<
+ indent() << "}" << endl <<
+ indent() << "break;" << endl;
indent_down();
}
- indent(out) << "default: " << endl;
+ indent(out) <<
+ "default: " << endl;
indent_up();
indent(out) << "TProtocolUtil.Skip(iprot, field.Type);" << endl;
indent(out) << "break;" << endl;
@@ -960,11 +936,13 @@ void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct*
scope_down(out);
- indent(out) << "iprot.ReadFieldEnd();" << endl;
+ indent(out) <<
+ "iprot.ReadFieldEnd();" << endl;
scope_down(out);
- indent(out) << "iprot.ReadStructEnd();" << endl;
+ indent(out) <<
+ "iprot.ReadStructEnd();" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (field_is_required((*f_iter))) {
@@ -978,18 +956,22 @@ void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct*
indent_down();
indent(out) << "}" << endl << endl;
+
}
void t_csharp_generator::generate_csharp_struct_writer(ofstream& out, t_struct* tstruct) {
- out << indent() << "public void Write(TProtocol oprot) {" << endl;
+ out <<
+ indent() << "public void Write(TProtocol oprot) {" << endl;
indent_up();
string name = tstruct->get_name();
const vector<t_field*>& fields = tstruct->get_sorted_members();
vector<t_field*>::const_iterator f_iter;
- indent(out) << "TStruct struc = new TStruct(\"" << name << "\");" << endl;
- indent(out) << "oprot.WriteStructBegin(struc);" << endl;
+ indent(out) <<
+ "TStruct struc = new TStruct(\"" << name << "\");" << endl;
+ indent(out) <<
+ "oprot.WriteStructBegin(struc);" << endl;
if (fields.size() > 0) {
indent(out) << "TField field = new TField();" << endl;
@@ -1002,11 +984,12 @@ void t_csharp_generator::generate_csharp_struct_writer(ofstream& out, t_struct*
} else if (!is_required) {
bool null_allowed = type_can_be_null((*f_iter)->get_type());
if (null_allowed) {
- indent(out) << "if (" << prop_name((*f_iter)) << " != null && __isset."
- << normalize_name((*f_iter)->get_name()) << ") {" << endl;
+ indent(out) <<
+ "if (" << prop_name((*f_iter)) << " != null && __isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
indent_up();
} else {
- indent(out) << "if (__isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
+ indent(out) <<
+ "if (__isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
indent_up();
}
}
@@ -1034,15 +1017,18 @@ void t_csharp_generator::generate_csharp_struct_writer(ofstream& out, t_struct*
}
void t_csharp_generator::generate_csharp_struct_result_writer(ofstream& out, t_struct* tstruct) {
- indent(out) << "public void Write(TProtocol oprot) {" << endl;
+ indent(out) <<
+ "public void Write(TProtocol oprot) {" << endl;
indent_up();
string name = tstruct->get_name();
const vector<t_field*>& fields = tstruct->get_sorted_members();
vector<t_field*>::const_iterator f_iter;
- indent(out) << "TStruct struc = new TStruct(\"" << name << "\");" << endl;
- indent(out) << "oprot.WriteStructBegin(struc);" << endl;
+ indent(out) <<
+ "TStruct struc = new TStruct(\"" << name << "\");" << endl;
+ indent(out) <<
+ "oprot.WriteStructBegin(struc);" << endl;
if (fields.size() > 0) {
indent(out) << "TField field = new TField();" << endl;
@@ -1064,18 +1050,24 @@ void t_csharp_generator::generate_csharp_struct_result_writer(ofstream& out, t_s
bool null_allowed = !nullable_ && type_can_be_null((*f_iter)->get_type());
if (null_allowed) {
- indent(out) << "if (" << prop_name(*f_iter) << " != null) {" << endl;
+ indent(out) <<
+ "if (" << prop_name(*f_iter) << " != null) {" << endl;
indent_up();
}
- indent(out) << "field.Name = \"" << prop_name(*f_iter) << "\";" << endl;
- indent(out) << "field.Type = " << type_to_enum((*f_iter)->get_type()) << ";" << endl;
- indent(out) << "field.ID = " << (*f_iter)->get_key() << ";" << endl;
- indent(out) << "oprot.WriteFieldBegin(field);" << endl;
+ indent(out) <<
+ "field.Name = \"" << prop_name(*f_iter) << "\";" << endl;
+ indent(out) <<
+ "field.Type = " << type_to_enum((*f_iter)->get_type()) << ";" << endl;
+ indent(out) <<
+ "field.ID = " << (*f_iter)->get_key() << ";" << endl;
+ indent(out) <<
+ "oprot.WriteFieldBegin(field);" << endl;
generate_serialize_field(out, *f_iter);
- indent(out) << "oprot.WriteFieldEnd();" << endl;
+ indent(out) <<
+ "oprot.WriteFieldEnd();" << endl;
if (null_allowed) {
indent_down();
@@ -1087,34 +1079,38 @@ void t_csharp_generator::generate_csharp_struct_result_writer(ofstream& out, t_s
}
}
- out << endl << indent() << "oprot.WriteFieldStop();" << endl << indent()
- << "oprot.WriteStructEnd();" << endl;
+ out <<
+ endl <<
+ indent() << "oprot.WriteFieldStop();" << endl <<
+ indent() << "oprot.WriteStructEnd();" << endl;
indent_down();
- indent(out) << "}" << endl << endl;
+ indent(out) <<
+ "}" << endl << endl;
}
void t_csharp_generator::generate_csharp_struct_tostring(ofstream& out, t_struct* tstruct) {
- indent(out) << "public override string ToString() {" << endl;
+ indent(out) <<
+ "public override string ToString() {" << endl;
indent_up();
- indent(out) << "StringBuilder __sb = new StringBuilder(\"" << tstruct->get_name() << "(\");"
- << endl;
+ indent(out) <<
+ "StringBuilder __sb = new StringBuilder(\"" << tstruct->get_name() << "(\");" << endl;
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
bool useFirstFlag = false;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if (!field_is_required((*f_iter))) {
+ if( ! field_is_required((*f_iter))) {
indent(out) << "bool __first = true;" << endl;
useFirstFlag = true;
}
break;
}
- bool had_required = false; // set to true after first required field has been processed
+ bool had_required = false; // set to true after first required field has been processed
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
bool is_required = field_is_required((*f_iter));
@@ -1125,55 +1121,66 @@ void t_csharp_generator::generate_csharp_struct_tostring(ofstream& out, t_struct
} else if (!is_required) {
bool null_allowed = type_can_be_null((*f_iter)->get_type());
if (null_allowed) {
- indent(out) << "if (" << prop_name((*f_iter)) << " != null && __isset."
- << normalize_name((*f_iter)->get_name()) << ") {" << endl;
+ indent(out) <<
+ "if (" << prop_name((*f_iter)) << " != null && __isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
indent_up();
} else {
- indent(out) << "if (__isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
+ indent(out) <<
+ "if (__isset." << normalize_name((*f_iter)->get_name()) << ") {" << endl;
indent_up();
}
}
- if (useFirstFlag && (!had_required)) {
+ if( useFirstFlag && (! had_required)) {
indent(out) << "if(!__first) { __sb.Append(\", \"); }" << endl;
- if (!is_required) {
+ if( ! is_required) {
indent(out) << "__first = false;" << endl;
}
- indent(out) << "__sb.Append(\"" << prop_name((*f_iter)) << ": \");" << endl;
+ indent(out) <<
+ "__sb.Append(\"" << prop_name((*f_iter)) << ": \");" << endl;
} else {
- indent(out) << "__sb.Append(\", " << prop_name((*f_iter)) << ": \");" << endl;
+ indent(out) <<
+ "__sb.Append(\", " << prop_name((*f_iter)) << ": \");" << endl;
}
+
t_type* ttype = (*f_iter)->get_type();
if (ttype->is_xception() || ttype->is_struct()) {
- indent(out) << "__sb.Append(" << prop_name((*f_iter))
- << "== null ? \"<null>\" : " << prop_name((*f_iter)) << ".ToString());" << endl;
+ indent(out) <<
+ "__sb.Append(" << prop_name((*f_iter)) << "== null ? \"<null>\" : "<< prop_name((*f_iter)) << ".ToString());" << endl;
} else {
- indent(out) << "__sb.Append(" << prop_name((*f_iter)) << ");" << endl;
+ indent(out) <<
+ "__sb.Append(" << prop_name((*f_iter)) << ");" << endl;
}
if (!is_required) {
indent_down();
indent(out) << "}" << endl;
} else {
- had_required = true; // now __first must be false, so we don't need to check it anymore
+ had_required = true; // now __first must be false, so we don't need to check it anymore
}
}
- indent(out) << "__sb.Append(\")\");" << endl;
- indent(out) << "return __sb.ToString();" << endl;
+ indent(out) <<
+ "__sb.Append(\")\");" << endl;
+ indent(out) <<
+ "return __sb.ToString();" << endl;
indent_down();
indent(out) << "}" << endl << endl;
}
+
void t_csharp_generator::generate_csharp_union(t_struct* tunion) {
string f_union_name = namespace_dir_ + "/" + (tunion->get_name()) + ".cs";
ofstream f_union;
f_union.open(f_union_name.c_str());
- f_union << autogen_comment() << csharp_type_usings() << csharp_thrift_usings() << endl;
+ f_union <<
+ autogen_comment() <<
+ csharp_type_usings() <<
+ csharp_thrift_usings() << endl;
generate_csharp_union_definition(f_union, tunion);
@@ -1184,8 +1191,7 @@ void t_csharp_generator::generate_csharp_union_definition(std::ofstream& out, t_
// Let's define the class first
start_csharp_namespace(out);
- indent(out) << "public abstract partial class " << tunion->get_name() << " : TAbstractBase {"
- << endl;
+ indent(out) << "public abstract partial class " << tunion->get_name() << " : TAbstractBase {" << endl;
indent_up();
@@ -1208,8 +1214,7 @@ void t_csharp_generator::generate_csharp_union_definition(std::ofstream& out, t_
indent(out) << "public override void Write(TProtocol protocol) {" << endl;
indent_up();
- indent(out) << "throw new TProtocolException( TProtocolException.INVALID_DATA, \"Cannot persist "
- "an union type which is not set.\");" << endl;
+ indent(out) << "throw new TProtocolException( TProtocolException.INVALID_DATA, \"Cannot persist an union type which is not set.\");" << endl;
indent_down();
indent(out) << "}" << endl << endl;
@@ -1231,16 +1236,12 @@ void t_csharp_generator::generate_csharp_union_definition(std::ofstream& out, t_
end_csharp_namespace(out);
}
-void t_csharp_generator::generate_csharp_union_class(std::ofstream& out,
- t_struct* tunion,
- t_field* tfield) {
- indent(out) << "public class " << tfield->get_name() << " : " << tunion->get_name() << " {"
- << endl;
+void t_csharp_generator::generate_csharp_union_class(std::ofstream& out, t_struct* tunion, t_field* tfield) {
+ indent(out) << "public class " << tfield->get_name() << " : " << tunion->get_name() << " {" << endl;
indent_up();
indent(out) << "private " << type_name(tfield->get_type()) << " _data;" << endl;
indent(out) << "public override object Data { get { return _data; } }" << endl;
- indent(out) << "public " << tfield->get_name() << "(" << type_name(tfield->get_type())
- << " data) : base(true) {" << endl;
+ indent(out) << "public " << tfield->get_name() << "(" << type_name(tfield->get_type()) << " data) : base(true) {" << endl;
indent_up();
indent(out) << "this._data = data;" << endl;
indent_down();
@@ -1268,6 +1269,7 @@ void t_csharp_generator::generate_csharp_union_class(std::ofstream& out,
indent(out) << "}" << endl << endl;
}
+
void t_csharp_generator::generate_csharp_struct_equals(ofstream& out, t_struct* tstruct) {
indent(out) << "public override bool Equals(object that) {" << endl;
indent_up();
@@ -1291,9 +1293,9 @@ void t_csharp_generator::generate_csharp_struct_equals(ofstream& out, t_struct*
indent(out) << "&& ";
}
if (!field_is_required((*f_iter)) && !(nullable_ && !field_has_default((*f_iter)))) {
- out << "((__isset." << normalize_name((*f_iter)->get_name()) << " == other.__isset."
- << normalize_name((*f_iter)->get_name()) << ") && ((!__isset."
- << normalize_name((*f_iter)->get_name()) << ") || (";
+ out << "((__isset." << normalize_name((*f_iter)->get_name())
+ << " == other.__isset." << normalize_name((*f_iter)->get_name())
+ << ") && ((!__isset." << normalize_name((*f_iter)->get_name()) << ") || (";
}
t_type* ttype = (*f_iter)->get_type();
if (ttype->is_container()) {
@@ -1332,16 +1334,20 @@ void t_csharp_generator::generate_csharp_struct_hashcode(ofstream& out, t_struct
t_type* ttype = (*f_iter)->get_type();
indent(out) << "hashcode = (hashcode * 397) ^ ";
if (field_is_required((*f_iter))) {
- out << "(";
- } else if (nullable_) {
+ out << "(";
+ } else if ( nullable_) {
out << "(" << prop_name((*f_iter)) << " == null ? 0 : ";
- } else {
+ }else {
out << "(!__isset." << normalize_name((*f_iter)->get_name()) << " ? 0 : ";
}
if (ttype->is_container()) {
- out << "(TCollections.GetHashCode(" << prop_name((*f_iter)) << "))";
+ out << "(TCollections.GetHashCode("
+ << prop_name((*f_iter))
+ << "))";
} else {
- out << "(" << prop_name((*f_iter)) << ".GetHashCode())";
+ out << "("
+ << prop_name((*f_iter))
+ << ".GetHashCode())";
}
out << ");" << endl;
}
@@ -1358,11 +1364,15 @@ void t_csharp_generator::generate_service(t_service* tservice) {
string f_service_name = namespace_dir_ + "/" + service_name_ + ".cs";
f_service_.open(f_service_name.c_str());
- f_service_ << autogen_comment() << csharp_type_usings() << csharp_thrift_usings() << endl;
+ f_service_ <<
+ autogen_comment() <<
+ csharp_type_usings() <<
+ csharp_thrift_usings() << endl;
start_csharp_namespace(f_service_);
- indent(f_service_) << "public partial class " << normalize_name(service_name_) << " {" << endl;
+ indent(f_service_) <<
+ "public partial class " << normalize_name(service_name_) << " {" << endl;
indent_up();
generate_service_interface(tservice);
@@ -1372,7 +1382,8 @@ void t_csharp_generator::generate_service(t_service* tservice) {
indent_down();
- indent(f_service_) << "}" << endl;
+ indent(f_service_) <<
+ "}" << endl;
end_csharp_namespace(f_service_);
f_service_.close();
}
@@ -1388,43 +1399,51 @@ void t_csharp_generator::generate_service_interface(t_service* tservice) {
generate_csharp_doc(f_service_, tservice);
if (wcf_) {
- indent(f_service_) << "[ServiceContract(Namespace=\"" << wcf_namespace_ << "\")]" << endl;
+ indent(f_service_) <<
+ "[ServiceContract(Namespace=\"" << wcf_namespace_ << "\")]" << endl;
}
- indent(f_service_) << "public interface Iface" << extends_iface << " {" << endl;
+ indent(f_service_) <<
+ "public interface Iface" << extends_iface << " {" << endl;
indent_up();
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- generate_csharp_doc(f_service_, *f_iter);
-
- // if we're using WCF, add the corresponding attributes
- if (wcf_) {
- indent(f_service_) << "[OperationContract]" << endl;
-
- const std::vector<t_field*>& xceptions = (*f_iter)->get_xceptions()->get_members();
- vector<t_field*>::const_iterator x_iter;
- for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- indent(f_service_) << "[FaultContract(typeof("
- + type_name((*x_iter)->get_type(), false, false) + "Fault))]" << endl;
- }
- }
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter)
+ {
+ generate_csharp_doc(f_service_, *f_iter);
+
+ // if we're using WCF, add the corresponding attributes
+ if (wcf_) {
+ indent(f_service_) <<
+ "[OperationContract]" << endl;
+
+ const std::vector<t_field*>& xceptions = (*f_iter)->get_xceptions()->get_members();
+ vector<t_field*>::const_iterator x_iter;
+ for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
+ indent(f_service_) << "[FaultContract(typeof(" + type_name((*x_iter)->get_type(), false, false) + "Fault))]" << endl;
+ }
+ }
- indent(f_service_) << function_signature(*f_iter) << ";" << endl;
- if (!async_) {
+ indent(f_service_) <<
+ function_signature(*f_iter) << ";" << endl;
+ if(!async_) {
indent(f_service_) << "#if SILVERLIGHT" << endl;
}
- indent(f_service_) << function_signature_async_begin(*f_iter, "Begin_") << ";" << endl;
- indent(f_service_) << function_signature_async_end(*f_iter, "End_") << ";" << endl;
- if (async_ || async_ctp_) {
- indent(f_service_) << function_signature_async(*f_iter) << ";" << endl;
+ indent(f_service_) <<
+ function_signature_async_begin(*f_iter, "Begin_") << ";" << endl;
+ indent(f_service_) <<
+ function_signature_async_end(*f_iter, "End_") << ";" << endl;
+ if(async_||async_ctp_) {
+ indent(f_service_) <<
+ function_signature_async(*f_iter) << ";" << endl;
}
if (!async_) {
indent(f_service_) << "#endif" << endl;
}
}
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_ <<
+ indent() << "}" << endl << endl;
}
void t_csharp_generator::generate_service_helpers(t_service* tservice) {
@@ -1450,14 +1469,17 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
generate_csharp_doc(f_service_, tservice);
- indent(f_service_) << "public class Client : " << extends_client << "Iface {" << endl;
+ indent(f_service_) <<
+ "public class Client : " << extends_client << "Iface {" << endl;
indent_up();
- indent(f_service_) << "public Client(TProtocol prot) : this(prot, prot)" << endl;
+ indent(f_service_) <<
+ "public Client(TProtocol prot) : this(prot, prot)" << endl;
scope_up(f_service_);
scope_down(f_service_);
f_service_ << endl;
- indent(f_service_) << "public Client(TProtocol iprot, TProtocol oprot)";
+ indent(f_service_) <<
+ "public Client(TProtocol iprot, TProtocol oprot)";
if (!extends.empty()) {
f_service_ << " : base(iprot, oprot)";
}
@@ -1465,16 +1487,19 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
scope_up(f_service_);
if (extends.empty()) {
- f_service_ << indent() << "iprot_ = iprot;" << endl << indent() << "oprot_ = oprot;" << endl;
+ f_service_ <<
+ indent() << "iprot_ = iprot;" << endl <<
+ indent() << "oprot_ = oprot;" << endl;
}
scope_down(f_service_);
f_service_ << endl;
if (extends.empty()) {
- f_service_ << indent() << "protected TProtocol iprot_;" << endl << indent()
- << "protected TProtocol oprot_;" << endl << indent() << "protected int seqid_;"
- << endl << endl;
+ f_service_ <<
+ indent() << "protected TProtocol iprot_;" << endl <<
+ indent() << "protected TProtocol oprot_;" << endl <<
+ indent() << "protected int seqid_;" << endl << endl;
f_service_ << indent() << "public TProtocol InputProtocol" << endl;
scope_up(f_service_);
@@ -1528,13 +1553,14 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
indent(f_service_) << "#if SILVERLIGHT" << endl;
}
// Begin_
- indent(f_service_) << "public " << function_signature_async_begin(*f_iter, "Begin_") << endl;
+ indent(f_service_) <<
+ "public " << function_signature_async_begin(*f_iter, "Begin_") << endl;
scope_up(f_service_);
- indent(f_service_) << "return "
- << "send_" << funname << "(callback, state";
+ indent(f_service_) <<
+ "return " << "send_" << funname << "(callback, state";
t_struct* arg_struct = (*f_iter)->get_arglist();
- prepare_member_name_mapping(arg_struct);
+ prepare_member_name_mapping( arg_struct);
const vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator fld_iter;
@@ -1547,28 +1573,34 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
f_service_ << endl;
// End
- indent(f_service_) << "public " << function_signature_async_end(*f_iter, "End_") << endl;
+ indent(f_service_) <<
+ "public " << function_signature_async_end(*f_iter, "End_") << endl;
scope_up(f_service_);
- indent(f_service_) << "oprot_.Transport.EndFlush(asyncResult);" << endl;
+ indent(f_service_) <<
+ "oprot_.Transport.EndFlush(asyncResult);" << endl;
if (!(*f_iter)->is_oneway()) {
f_service_ << indent();
if (!(*f_iter)->get_returntype()->is_void()) {
f_service_ << "return ";
}
- f_service_ << "recv_" << funname << "();" << endl;
+ f_service_ <<
+ "recv_" << funname << "();" << endl;
}
scope_down(f_service_);
f_service_ << endl;
// async
bool first;
- if (async_ || async_ctp_) {
- indent(f_service_) << "public async " << function_signature_async(*f_iter, "") << endl;
+ if( async_||async_ctp_) {
+ indent(f_service_) <<
+ "public async " << function_signature_async(*f_iter, "") << endl;
scope_up(f_service_);
if (!(*f_iter)->get_returntype()->is_void()) {
- indent(f_service_) << type_name((*f_iter)->get_returntype()) << " retval;" << endl;
- indent(f_service_) << "retval = ";
+ indent(f_service_) <<
+ type_name( (*f_iter)->get_returntype()) << " retval;" << endl;
+ indent(f_service_) <<
+ "retval = ";
} else {
indent(f_service_);
}
@@ -1580,10 +1612,12 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
scope_up(f_service_);
indent(f_service_);
if (!(*f_iter)->get_returntype()->is_void()) {
- f_service_ << "return ";
+ f_service_ <<
+ "return ";
}
- f_service_ << funname << "(";
- first = true;
+ f_service_ <<
+ funname << "(";
+ first = true;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
if (first) {
first = false;
@@ -1594,11 +1628,13 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
}
f_service_ << ");" << endl;
indent_down();
- indent(f_service_) << "});" << endl;
+ indent(f_service_) <<
+ "});" << endl;
if (!(*f_iter)->get_returntype()->is_void()) {
- indent(f_service_) << "return retval;" << endl;
+ indent(f_service_) <<
+ "return retval;" << endl;
}
- scope_down(f_service_);
+ scope_down(f_service_);
f_service_ << endl;
}
@@ -1608,12 +1644,14 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
// "Normal" Synchronous invoke
generate_csharp_doc(f_service_, *f_iter);
- indent(f_service_) << "public " << function_signature(*f_iter) << endl;
+ indent(f_service_) <<
+ "public " << function_signature(*f_iter) << endl;
scope_up(f_service_);
if (!async_) {
indent(f_service_) << "#if !SILVERLIGHT" << endl;
- indent(f_service_) << "send_" << funname << "(";
+ indent(f_service_) <<
+ "send_" << funname << "(";
first = true;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
@@ -1631,7 +1669,8 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
if (!(*f_iter)->get_returntype()->is_void()) {
f_service_ << "return ";
}
- f_service_ << "recv_" << funname << "();" << endl;
+ f_service_ <<
+ "recv_" << funname << "();" << endl;
}
f_service_ << endl;
@@ -1650,7 +1689,8 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
if (!(*f_iter)->get_returntype()->is_void()) {
f_service_ << "return ";
}
- f_service_ << "End_" << funname << "(asyncResult);" << endl;
+ f_service_ <<
+ "End_" << funname << "(asyncResult);" << endl;
}
f_service_ << endl;
@@ -1661,8 +1701,8 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
// Send
t_function send_function(g_type_void,
- string("send_") + (*f_iter)->get_name(),
- (*f_iter)->get_arglist());
+ string("send_") + (*f_iter)->get_name(),
+ (*f_iter)->get_arglist());
string argsname = (*f_iter)->get_name() + "_args";
@@ -1677,19 +1717,20 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
}
scope_up(f_service_);
- f_service_ << indent() << "oprot_.WriteMessageBegin(new TMessage(\"" << funname << "\", "
- << ((*f_iter)->is_oneway() ? "TMessageType.Oneway" : "TMessageType.Call")
- << ", seqid_));" << endl << indent() << argsname << " args = new " << argsname
- << "();" << endl;
+ f_service_ <<
+ indent() << "oprot_.WriteMessageBegin(new TMessage(\"" << funname << "\", " <<
+ ((*f_iter)->is_oneway() ? "TMessageType.Oneway" : "TMessageType.Call") <<
+ ", seqid_));" << endl <<
+ indent() << argsname << " args = new " << argsname << "();" << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- f_service_ << indent() << "args." << prop_name(*fld_iter) << " = "
- << normalize_name((*fld_iter)->get_name()) << ";" << endl;
+ f_service_ <<
+ indent() << "args." << prop_name(*fld_iter) << " = " << normalize_name((*fld_iter)->get_name()) << ";" << endl;
}
- f_service_ << indent() << "args.Write(oprot_);" << endl << indent()
- << "oprot_.WriteMessageEnd();" << endl;
- ;
+ f_service_ <<
+ indent() << "args.Write(oprot_);" << endl <<
+ indent() << "oprot_.WriteMessageEnd();" << endl;;
if (!async_) {
indent(f_service_) << "#if SILVERLIGHT" << endl;
@@ -1701,7 +1742,7 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
indent(f_service_) << "#endif" << endl;
}
- cleanup_member_name_mapping(arg_struct);
+ cleanup_member_name_mapping( arg_struct);
scope_down(f_service_);
f_service_ << endl;
@@ -1710,72 +1751,85 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
t_struct noargs(program_);
t_function recv_function((*f_iter)->get_returntype(),
- string("recv_") + (*f_iter)->get_name(),
- &noargs,
- (*f_iter)->get_xceptions());
- indent(f_service_) << "public " << function_signature(&recv_function) << endl;
+ string("recv_") + (*f_iter)->get_name(),
+ &noargs,
+ (*f_iter)->get_xceptions());
+ indent(f_service_) <<
+ "public " << function_signature(&recv_function) << endl;
scope_up(f_service_);
- prepare_member_name_mapping((*f_iter)->get_xceptions());
+ prepare_member_name_mapping( (*f_iter)->get_xceptions());
- f_service_ << indent() << "TMessage msg = iprot_.ReadMessageBegin();" << endl << indent()
- << "if (msg.Type == TMessageType.Exception) {" << endl;
+ f_service_ <<
+ indent() << "TMessage msg = iprot_.ReadMessageBegin();" << endl <<
+ indent() << "if (msg.Type == TMessageType.Exception) {" << endl;
indent_up();
- f_service_ << indent() << "TApplicationException x = TApplicationException.Read(iprot_);"
- << endl << indent() << "iprot_.ReadMessageEnd();" << endl << indent() << "throw x;"
- << endl;
+ f_service_ <<
+ indent() << "TApplicationException x = TApplicationException.Read(iprot_);" << endl <<
+ indent() << "iprot_.ReadMessageEnd();" << endl <<
+ indent() << "throw x;" << endl;
indent_down();
- f_service_ << indent() << "}" << endl << indent() << resultname << " result = new "
- << resultname << "();" << endl << indent() << "result.Read(iprot_);" << endl
- << indent() << "iprot_.ReadMessageEnd();" << endl;
+ f_service_ <<
+ indent() << "}" << endl <<
+ indent() << resultname << " result = new " << resultname << "();" << endl <<
+ indent() << "result.Read(iprot_);" << endl <<
+ indent() << "iprot_.ReadMessageEnd();" << endl;
if (!(*f_iter)->get_returntype()->is_void()) {
if (nullable_) {
if (type_can_be_null((*f_iter)->get_returntype())) {
- f_service_ << indent() << "if (result.Success != null) {" << endl << indent()
- << " return result.Success;" << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result.Success != null) {" << endl <<
+ indent() << " return result.Success;" << endl <<
+ indent() << "}" << endl;
} else {
- f_service_ << indent() << "if (result.Success.HasValue) {" << endl << indent()
- << " return result.Success.Value;" << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result.Success.HasValue) {" << endl <<
+ indent() << " return result.Success.Value;" << endl <<
+ indent() << "}" << endl;
}
} else {
- f_service_ << indent() << "if (result.__isset.success) {" << endl << indent()
- << " return result.Success;" << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result.__isset.success) {" << endl <<
+ indent() << " return result.Success;" << endl <<
+ indent() << "}" << endl;
}
}
- t_struct* xs = (*f_iter)->get_xceptions();
+ t_struct *xs = (*f_iter)->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
if (nullable_) {
- f_service_ << indent() << "if (result." << prop_name(*x_iter) << " != null) {" << endl
- << indent() << " throw result." << prop_name(*x_iter) << ";" << endl
- << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result." << prop_name(*x_iter) << " != null) {" << endl <<
+ indent() << " throw result." << prop_name(*x_iter) << ";" << endl <<
+ indent() << "}" << endl;
} else {
- f_service_ << indent() << "if (result.__isset." << normalize_name((*x_iter)->get_name())
- << ") {" << endl << indent() << " throw result." << prop_name(*x_iter) << ";"
- << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result.__isset." << normalize_name((*x_iter)->get_name()) << ") {" << endl <<
+ indent() << " throw result." << prop_name(*x_iter) << ";" << endl <<
+ indent() << "}" << endl;
}
}
if ((*f_iter)->get_returntype()->is_void()) {
- indent(f_service_) << "return;" << endl;
+ indent(f_service_) <<
+ "return;" << endl;
} else {
- f_service_ << indent()
- << "throw new "
- "TApplicationException(TApplicationException.ExceptionType.MissingResult, \""
- << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
+ f_service_ <<
+ indent() << "throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, \"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
}
- cleanup_member_name_mapping((*f_iter)->get_xceptions());
+ cleanup_member_name_mapping( (*f_iter)->get_xceptions());
scope_down(f_service_);
f_service_ << endl;
}
}
indent_down();
- indent(f_service_) << "}" << endl;
+ indent(f_service_) <<
+ "}" << endl;
}
void t_csharp_generator::generate_service_server(t_service* tservice) {
@@ -1789,84 +1843,98 @@ void t_csharp_generator::generate_service_server(t_service* tservice) {
extends_processor = extends + ".Processor, ";
}
- indent(f_service_) << "public class Processor : " << extends_processor << "TProcessor {" << endl;
+ indent(f_service_) <<
+ "public class Processor : " << extends_processor << "TProcessor {" << endl;
indent_up();
- indent(f_service_) << "public Processor(Iface iface)";
+ indent(f_service_) <<
+ "public Processor(Iface iface)" ;
if (!extends.empty()) {
f_service_ << " : base(iface)";
}
f_service_ << endl;
scope_up(f_service_);
- f_service_ << indent() << "iface_ = iface;" << endl;
+ f_service_ <<
+ indent() << "iface_ = iface;" << endl;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- f_service_ << indent() << "processMap_[\"" << (*f_iter)->get_name()
- << "\"] = " << (*f_iter)->get_name() << "_Process;" << endl;
+ f_service_ <<
+ indent() << "processMap_[\"" << (*f_iter)->get_name() << "\"] = " << (*f_iter)->get_name() << "_Process;" << endl;
}
scope_down(f_service_);
f_service_ << endl;
if (extends.empty()) {
- f_service_
- << indent()
- << "protected delegate void ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot);"
- << endl;
+ f_service_ <<
+ indent() << "protected delegate void ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot);" << endl;
}
- f_service_ << indent() << "private Iface iface_;" << endl;
+ f_service_ <<
+ indent() << "private Iface iface_;" << endl;
if (extends.empty()) {
- f_service_ << indent() << "protected Dictionary<string, ProcessFunction> processMap_ = new "
- "Dictionary<string, ProcessFunction>();" << endl;
+ f_service_ <<
+ indent() << "protected Dictionary<string, ProcessFunction> processMap_ = new Dictionary<string, ProcessFunction>();" << endl;
}
f_service_ << endl;
if (extends.empty()) {
- indent(f_service_) << "public bool Process(TProtocol iprot, TProtocol oprot)" << endl;
- } else {
- indent(f_service_) << "public new bool Process(TProtocol iprot, TProtocol oprot)" << endl;
+ indent(f_service_) <<
+ "public bool Process(TProtocol iprot, TProtocol oprot)" << endl;
+ }
+ else
+ {
+ indent(f_service_) <<
+ "public new bool Process(TProtocol iprot, TProtocol oprot)" << endl;
}
scope_up(f_service_);
- f_service_ << indent() << "try" << endl;
+ f_service_ << indent() << "try" << endl;
scope_up(f_service_);
- f_service_ << indent() << "TMessage msg = iprot.ReadMessageBegin();" << endl;
-
- f_service_
- << indent() << "ProcessFunction fn;" << endl << indent()
- << "processMap_.TryGetValue(msg.Name, out fn);" << endl << indent() << "if (fn == null) {"
- << endl << indent() << " TProtocolUtil.Skip(iprot, TType.Struct);" << endl << indent()
- << " iprot.ReadMessageEnd();" << endl << indent()
- << " TApplicationException x = new TApplicationException "
- "(TApplicationException.ExceptionType.UnknownMethod, \"Invalid method name: '\" + "
- "msg.Name + \"'\");" << endl << indent()
- << " oprot.WriteMessageBegin(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID));"
- << endl << indent() << " x.Write(oprot);" << endl << indent() << " oprot.WriteMessageEnd();"
- << endl << indent() << " oprot.Transport.Flush();" << endl << indent() << " return true;"
- << endl << indent() << "}" << endl << indent() << "fn(msg.SeqID, iprot, oprot);" << endl;
+ f_service_ <<
+ indent() << "TMessage msg = iprot.ReadMessageBegin();" << endl;
+
+ f_service_ <<
+ indent() << "ProcessFunction fn;" << endl <<
+ indent() << "processMap_.TryGetValue(msg.Name, out fn);" << endl <<
+ indent() << "if (fn == null) {" << endl <<
+ indent() << " TProtocolUtil.Skip(iprot, TType.Struct);" << endl <<
+ indent() << " iprot.ReadMessageEnd();" << endl <<
+ indent() << " TApplicationException x = new TApplicationException (TApplicationException.ExceptionType.UnknownMethod, \"Invalid method name: '\" + msg.Name + \"'\");" << endl <<
+ indent() << " oprot.WriteMessageBegin(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID));" << endl <<
+ indent() << " x.Write(oprot);" << endl <<
+ indent() << " oprot.WriteMessageEnd();" << endl <<
+ indent() << " oprot.Transport.Flush();" << endl <<
+ indent() << " return true;" << endl <<
+ indent() << "}" << endl <<
+ indent() << "fn(msg.SeqID, iprot, oprot);" << endl;
scope_down(f_service_);
- f_service_ << indent() << "catch (IOException)" << endl;
+ f_service_ <<
+ indent() << "catch (IOException)" << endl;
scope_up(f_service_);
- f_service_ << indent() << "return false;" << endl;
+ f_service_ <<
+ indent() << "return false;" << endl;
scope_down(f_service_);
- f_service_ << indent() << "return true;" << endl;
+ f_service_ <<
+ indent() << "return true;" << endl;
scope_down(f_service_);
f_service_ << endl;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter)
+ {
generate_process_function(tservice, *f_iter);
}
indent_down();
- indent(f_service_) << "}" << endl << endl;
+ indent(f_service_) <<
+ "}" << endl << endl;
}
void t_csharp_generator::generate_function_helpers(t_function* tfunction) {
@@ -1880,7 +1948,7 @@ void t_csharp_generator::generate_function_helpers(t_function* tfunction) {
result.append(&success);
}
- t_struct* xs = tfunction->get_xceptions();
+ t_struct *xs = tfunction->get_xceptions();
const vector<t_field*>& fields = xs->get_members();
vector<t_field*>::const_iterator f_iter;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
@@ -1891,27 +1959,31 @@ void t_csharp_generator::generate_function_helpers(t_function* tfunction) {
}
void t_csharp_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
- (void)tservice;
- indent(f_service_) << "public void " << tfunction->get_name()
- << "_Process(int seqid, TProtocol iprot, TProtocol oprot)" << endl;
+ (void) tservice;
+ indent(f_service_) <<
+ "public void " << tfunction->get_name() << "_Process(int seqid, TProtocol iprot, TProtocol oprot)" << endl;
scope_up(f_service_);
string argsname = tfunction->get_name() + "_args";
string resultname = tfunction->get_name() + "_result";
- f_service_ << indent() << argsname << " args = new " << argsname << "();" << endl << indent()
- << "args.Read(iprot);" << endl << indent() << "iprot.ReadMessageEnd();" << endl;
+ f_service_ <<
+ indent() << argsname << " args = new " << argsname << "();" << endl <<
+ indent() << "args.Read(iprot);" << endl <<
+ indent() << "iprot.ReadMessageEnd();" << endl;
t_struct* xs = tfunction->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
if (!tfunction->is_oneway()) {
- f_service_ << indent() << resultname << " result = new " << resultname << "();" << endl;
+ f_service_ <<
+ indent() << resultname << " result = new " << resultname << "();" << endl;
}
if (xceptions.size() > 0) {
- f_service_ << indent() << "try {" << endl;
+ f_service_ <<
+ indent() << "try {" << endl;
indent_up();
}
@@ -1923,7 +1995,8 @@ void t_csharp_generator::generate_process_function(t_service* tservice, t_functi
if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
f_service_ << "result.Success = ";
}
- f_service_ << "iface_." << normalize_name(tfunction->get_name()) << "(";
+ f_service_ <<
+ "iface_." << normalize_name(tfunction->get_name()) << "(";
bool first = true;
prepare_member_name_mapping(arg_struct);
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
@@ -1943,35 +2016,36 @@ void t_csharp_generator::generate_process_function(t_service* tservice, t_functi
if (!tfunction->is_oneway() && xceptions.size() > 0) {
indent_down();
f_service_ << indent() << "}";
- prepare_member_name_mapping(xs);
+ prepare_member_name_mapping( xs);
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << " catch (" << type_name((*x_iter)->get_type(), false, false) << " "
- << (*x_iter)->get_name() << ") {" << endl;
+ f_service_ << " catch (" << type_name((*x_iter)->get_type(), false, false) << " " << (*x_iter)->get_name() << ") {" << endl;
if (!tfunction->is_oneway()) {
indent_up();
- f_service_ << indent() << "result." << prop_name(*x_iter) << " = " << (*x_iter)->get_name()
- << ";" << endl;
+ f_service_ <<
+ indent() << "result." << prop_name(*x_iter) << " = " << (*x_iter)->get_name() << ";" << endl;
indent_down();
f_service_ << indent() << "}";
} else {
f_service_ << "}";
}
}
- cleanup_member_name_mapping(xs);
+ cleanup_member_name_mapping( xs);
f_service_ << endl;
}
if (tfunction->is_oneway()) {
- f_service_ << indent() << "return;" << endl;
+ f_service_ <<
+ indent() << "return;" << endl;
scope_down(f_service_);
return;
}
- f_service_ << indent() << "oprot.WriteMessageBegin(new TMessage(\"" << tfunction->get_name()
- << "\", TMessageType.Reply, seqid)); " << endl << indent() << "result.Write(oprot);"
- << endl << indent() << "oprot.WriteMessageEnd();" << endl << indent()
- << "oprot.Transport.Flush();" << endl;
+ f_service_ <<
+ indent() << "oprot.WriteMessageBegin(new TMessage(\"" << tfunction->get_name() << "\", TMessageType.Reply, seqid)); " << endl <<
+ indent() << "result.Write(oprot);" << endl <<
+ indent() << "oprot.WriteMessageEnd();" << endl <<
+ indent() << "oprot.Transport.Flush();" << endl;
scope_down(f_service_);
@@ -2000,7 +2074,8 @@ void t_csharp_generator::generate_csharp_union_reader(std::ofstream& out, t_stru
scope_up(out);
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- indent(out) << "case " << (*f_iter)->get_key() << ":" << endl;
+ indent(out) <<
+ "case " << (*f_iter)->get_ke
<TRUNCATED>