Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,16 @@ void t_netstd_generator::generate_service_interface(ostream& out, t_service* tse
}
}

auto iter = (*f_iter)->annotations_.find("deprecated");
if( (*f_iter)->annotations_.end() != iter) {
out << indent() << "[Obsolete";
// empty annotation values end up with "1" somewhere, ignore these as well
if ((iter->second.length() > 0) && (iter->second != "1")) {
out << "(" << make_csharp_string_literal(iter->second) << ")";
}
out << "]" << endl;
}

out << indent() << function_signature_async(*f_iter) << ";" << endl << endl;
}
indent_down();
Expand Down Expand Up @@ -2312,6 +2322,11 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service
const vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator f_iter;

bool is_deprecated = (tfunction->annotations_.end() != tfunction->annotations_.find("deprecated"));
if( is_deprecated) {
out << indent() << "#pragma warning disable CS0618,CS0612" << endl;
}

out << indent();
if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void())
{
Expand Down Expand Up @@ -2346,6 +2361,10 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service

out << "cancellationToken);" << endl;

if( is_deprecated) {
out << indent() << "#pragma warning restore CS0618,CS0612" << endl;
}

vector<t_field*>::const_iterator x_iter;

collect_extensions_types(xs);
Expand Down Expand Up @@ -2947,6 +2966,30 @@ void t_netstd_generator::generate_netstd_property(ostream& out, t_field* tfield,
out << endl;
}

string t_netstd_generator::make_csharp_string_literal( string const& value)
{
if (value.length() == 0) {
return "";
}

std::stringstream result;
result << "\"";
for (signed char const c: value) {
if( (c >= 0) && (c < 32)) { // convert ctrl chars, but leave UTF-8 alone
int width = std::max( (int)sizeof(c), 4);
result << "\\x" << std::hex << std::setw(width) << std::setfill('0') << (int)c;
} else if ((c == '\\') || (c == '"')) {
result << "\\" << c;
} else {
result << c; // anything else "as is"
}
}
result << "\"";

return result.str();
}


string t_netstd_generator::make_valid_csharp_identifier(string const& fromName)
{
string str = fromName;
Expand Down
1 change: 1 addition & 0 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class t_netstd_generator : public t_oop_generator
void init_keywords();
string normalize_name(string name);
string make_valid_csharp_identifier(string const& fromName);
string make_csharp_string_literal( string const& value);
void prepare_member_name_mapping(t_service* tservice);
void prepare_member_name_mapping(t_struct* tstruct);
void prepare_member_name_mapping(t_struct* scope, const vector<t_field*>& members, const string& structname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,11 @@ service foobar {
set<set<set<Distance>>> DoItNow( 1 : list<list<list<RaceDetails>>> rd, 2: i32 mitDefault = 42) throws (1: CrashBoomBang cbb)
}

service deprecate_everything {
void Foo( ) ( deprecated = "This method has neither 'x' nor \"y\"" )
void Bar( ) ( deprecated = "Fails to deliver 中文 колбаса" )
void Baz( ) ( deprecated = "Need this to work with tabs (\t) or Umlauts (äöüÄÖÜß) too" )
void Deprecated() ( deprecated ) // no comment
}