THRIFT-5746 Upgrade to net8
Client: netstd
Patch: Jens Geyer
diff --git a/build/docker/old/debian-stretch/Dockerfile b/build/docker/old/debian-stretch/Dockerfile
index 25237ca..f584bba 100644
--- a/build/docker/old/debian-stretch/Dockerfile
+++ b/build/docker/old/debian-stretch/Dockerfile
@@ -102,10 +102,10 @@
# project isn't ready for this quite yet:
# RUN apt-get install -y --no-install-recommends \
# `# dotnet core dependencies` \
-# dotnet-sdk-7.0 \
-# dotnet-runtime-7.0 \
-# aspnetcore-runtime-7.0 \
-# dotnet-apphost-pack-7.0
+# dotnet-sdk-8.0 \
+# dotnet-runtime-8.0 \
+# aspnetcore-runtime-8.0 \
+# dotnet-apphost-pack-8.0
RUN apt-get install -y --no-install-recommends \
`# Erlang dependencies` \
diff --git a/build/docker/old/ubuntu-artful/Dockerfile b/build/docker/old/ubuntu-artful/Dockerfile
index 0391470..f94b700 100644
--- a/build/docker/old/ubuntu-artful/Dockerfile
+++ b/build/docker/old/ubuntu-artful/Dockerfile
@@ -120,10 +120,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
RUN apt-get install -y --no-install-recommends \
`# Erlang dependencies` \
diff --git a/build/docker/old/ubuntu-disco/Dockerfile b/build/docker/old/ubuntu-disco/Dockerfile
index d2f397a..39642cf 100644
--- a/build/docker/old/ubuntu-disco/Dockerfile
+++ b/build/docker/old/ubuntu-disco/Dockerfile
@@ -126,10 +126,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
RUN apt-get install -y --no-install-recommends \
`# Erlang dependencies` \
diff --git a/build/docker/old/ubuntu-xenial/Dockerfile b/build/docker/old/ubuntu-xenial/Dockerfile
index 37df80f..d9d87cc 100644
--- a/build/docker/old/ubuntu-xenial/Dockerfile
+++ b/build/docker/old/ubuntu-xenial/Dockerfile
@@ -115,10 +115,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
# Erlang dependencies
ARG ERLANG_OTP_VERSION=20.3.8.9
diff --git a/build/docker/ubuntu-bionic/Dockerfile b/build/docker/ubuntu-bionic/Dockerfile
index 00c7de3..350921a 100644
--- a/build/docker/ubuntu-bionic/Dockerfile
+++ b/build/docker/ubuntu-bionic/Dockerfile
@@ -124,10 +124,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
# Erlang dependencies
ARG ERLANG_OTP_VERSION=23.3.4.11
diff --git a/build/docker/ubuntu-focal/Dockerfile b/build/docker/ubuntu-focal/Dockerfile
index 1039e45..416e806 100644
--- a/build/docker/ubuntu-focal/Dockerfile
+++ b/build/docker/ubuntu-focal/Dockerfile
@@ -125,10 +125,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
# Erlang dependencies
ARG ERLANG_OTP_VERSION=23.3.4.11
diff --git a/build/docker/ubuntu-jammy/Dockerfile b/build/docker/ubuntu-jammy/Dockerfile
index d45070f..a10fea6 100644
--- a/build/docker/ubuntu-jammy/Dockerfile
+++ b/build/docker/ubuntu-jammy/Dockerfile
@@ -125,10 +125,10 @@
RUN apt-get install -y --no-install-recommends \
`# dotnet core dependencies` \
- dotnet-sdk-7.0 \
- dotnet-runtime-7.0 \
- aspnetcore-runtime-7.0 \
- dotnet-apphost-pack-7.0
+ dotnet-sdk-8.0 \
+ dotnet-runtime-8.0 \
+ aspnetcore-runtime-8.0 \
+ dotnet-apphost-pack-8.0
# Erlang dependencies
ARG ERLANG_OTP_VERSION=23.3.4.11
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index 1c97002..1a27c0c 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -51,7 +51,7 @@
: t_oop_generator(program)
{
(void)option_string;
- use_net6_features = false;
+ target_net_version = 0;
suppress_deepcopy = false;
add_async_postfix = false;
use_pascal_case_properties = false;
@@ -83,7 +83,10 @@
suppress_deepcopy = true;
}
else if (iter->first.compare("net6") == 0) {
- use_net6_features = true;
+ target_net_version = 6;
+ }
+ else if (iter->first.compare("net8") == 0) {
+ target_net_version = 8;
}
else if (iter->first.compare("async_postfix") == 0) {
add_async_postfix = true;
@@ -153,13 +156,13 @@
}
pverbose(".NET Standard options:\n");
- pverbose("- union ........... %s\n", (is_union_enabled() ? "ON" : "off"));
- pverbose("- serialize ....... %s\n", (is_serialize_enabled() ? "ON" : "off"));
- pverbose("- wcf ............. %s\n", (is_wcf_enabled() ? "ON" : "off"));
- pverbose("- pascal .......... %s\n", (use_pascal_case_properties ? "ON" : "off"));
- pverbose("- net6 ............ %s\n", (use_net6_features ? "ON" : "off"));
- pverbose("- no_deepcopy ..... %s\n", (suppress_deepcopy ? "ON" : "off"));
- pverbose("- async_postfix ... %s\n", (add_async_postfix ? "ON" : "off"));
+ pverbose("- union ................ %s\n", (is_union_enabled() ? "ON" : "off"));
+ pverbose("- serialize ............ %s\n", (is_serialize_enabled() ? "ON" : "off"));
+ pverbose("- wcf .................. %s\n", (is_wcf_enabled() ? "ON" : "off"));
+ pverbose("- pascal ............... %s\n", (use_pascal_case_properties ? "ON" : "off"));
+ pverbose("- target NET version ... %d\n", target_net_version);
+ pverbose("- no_deepcopy .......... %s\n", (suppress_deepcopy ? "ON" : "off"));
+ pverbose("- async_postfix ........ %s\n", (add_async_postfix ? "ON" : "off"));
}
string t_netstd_generator::normalize_name(string name, bool is_arg_name)
@@ -180,7 +183,7 @@
}
// prevent CS8981 "The type name only contains lower-cased ascii characters"
- if( name.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == std::string::npos)
+ if( name.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == std::string::npos)
{
return "@" + name;
}
@@ -199,19 +202,24 @@
void t_netstd_generator::pragmas_and_directives(ostream& out)
{
- if( use_net6_features) {
+ if( target_net_version >= 6) {
+ out << "// Thrift code generated for net" << target_net_version << endl;
out << "#nullable enable // requires C# 8.0" << endl;
}
// this one must be first
out << "#pragma warning disable IDE0079 // remove unnecessary pragmas" << endl;
- out << "#pragma warning disable IDE0017 // object init can be simplified" << endl
- << "#pragma warning disable IDE0028 // collection init can be simplified" << endl
- << "#pragma warning disable IDE1006 // parts of the code use IDL spelling" << endl
- << "#pragma warning disable CA1822 // empty " << DEEP_COPY_METHOD_NAME << "() methods still non-static" << endl;
+ if( target_net_version >= 8) {
+ out << "#pragma warning disable IDE0290 // use primary CTOR" << endl;
+ } else {
+ out << "#pragma warning disable IDE0017 // object init can be simplified" << endl;
+ out << "#pragma warning disable IDE0028 // collection init can be simplified" << endl;
+ }
+ out << "#pragma warning disable IDE1006 // parts of the code use IDL spelling" << endl;
+ out << "#pragma warning disable CA1822 // empty " << DEEP_COPY_METHOD_NAME << "() methods still non-static" << endl;
- if( ! use_net6_features) {
+ if( target_net_version < 6) {
out << "#pragma warning disable IDE0083 // pattern matching \"that is not SomeType\" requires net5.0 but we still support earlier versions" << endl;
}
out << endl;
@@ -474,7 +482,13 @@
if (!defval || needtype)
{
- out << (in_static ? "" : type->is_base_type() ? "public const " : "public static ") << type_name(type) << " ";
+ if(in_static) {
+ out << type_name(type) << " ";
+ } else if(type->is_base_type()) {
+ out << "public const " << type_name(type) << " ";
+ } else {
+ out << "public static " << (target_net_version >= 6 ? "readonly " : "") << type_name(type) << " ";
+ }
}
if (type->is_base_type())
@@ -490,15 +504,21 @@
}
else if (type->is_struct() || type->is_xception())
{
- out << name << " = new " << type_name(type) << "();" << endl;
+ if(target_net_version >= 6) {
+ out << name << " = new();" << endl;
+ } else {
+ out << name << " = new " << type_name(type) << "();" << endl;
+ }
}
- else if (type->is_map())
+ else if (type->is_map() || type->is_list() || type->is_set())
{
- out << name << " = new " << type_name(type) << "();" << endl;
- }
- else if (type->is_list() || type->is_set())
- {
- out << name << " = new " << type_name(type) << "();" << endl;
+ if(target_net_version >= 8) {
+ out << name << " = [];" << endl;
+ } else if(target_net_version >= 6) {
+ out << name << " = new();" << endl;
+ } else {
+ out << name << " = new " << type_name(type) << "();" << endl;
+ }
}
if (defval && !type->is_base_type() && !type->is_enum())
@@ -667,7 +687,7 @@
{
out << indent() << "public static bool Equals(this " << iter->first << " instance, object that)" << endl;
scope_up(out);
- if( use_net6_features) {
+ if( target_net_version >= 6) {
out << indent() << "if (that is not " << iter->first << " other) return false;" << endl;
} else {
out << indent() << "if (!(that is " << iter->first << " other)) return false;" << endl;
@@ -705,7 +725,7 @@
out << indent() << "foreach (var pair in source)" << endl;
indent_up();
- if( use_net6_features) {
+ if( target_net_version >= 6) {
out << indent() << tmp_instance << ".Add(pair.Key" << copy_key;
out << ", pair.Value" << copy_val;
} else {
@@ -743,7 +763,7 @@
out << indent() << "foreach (var elem in source)" << endl;
indent_up();
- if( use_net6_features) {
+ if( target_net_version >= 6) {
out << indent() << tmp_instance << ".Add(elem" << copy_elm;
} else {
out << indent() << tmp_instance << ".Add(";
@@ -1077,7 +1097,14 @@
// return directly if there are only required fields
string tmp_instance = tmp("tmp");
- out << indent() << "var " << tmp_instance << " = new " << sharp_struct_name << "();" << endl;
+ out << indent() << "var " << tmp_instance << " = new " << sharp_struct_name << "()";
+ bool inline_assignment = (target_net_version >= 6);
+ if(inline_assignment) {
+ out << endl << indent() << "{" << endl;
+ indent_up();
+ } else {
+ out << endl;
+ }
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
bool needs_typecast = false;
@@ -1086,21 +1113,46 @@
string copy_op = get_deep_copy_method_call(ttype, true, needs_typecast, suffix);
bool is_required = field_is_required(*m_iter);
+ bool null_allowed = type_can_be_null((*m_iter)->get_type());
+
+ if(inline_assignment) {
+ if( null_allowed || (!is_required)) { // = has isset
+ indent_down();
+ out << indent() << "};" << endl;
+ inline_assignment = false;
+ }
+ }
+
generate_null_check_begin( out, *m_iter);
- out << indent() << tmp_instance << "." << prop_name(*m_iter) << " = ";
+ out << indent();
+ if(!inline_assignment) {
+ out << tmp_instance << ".";
+ }
+ out << prop_name(*m_iter) << " = ";
if( needs_typecast) {
out << "(" << type_name(ttype) << ")";
}
- out << "this." << prop_name(*m_iter) << copy_op << ";" << endl;
+ out << "this." << prop_name(*m_iter) << copy_op;
+ out << (inline_assignment ? "," : ";") << endl;
generate_null_check_end( out, *m_iter);
if( !is_required) {
- out << indent() << tmp_instance << ".__isset." << get_isset_name(normalize_name((*m_iter)->get_name()))
- << " = this.__isset." << get_isset_name(normalize_name((*m_iter)->get_name())) << ";" << endl;
+ out << indent();
+ if(!inline_assignment) {
+ out << tmp_instance << ".";
+ }
+ out << "__isset." << get_isset_name(normalize_name((*m_iter)->get_name()));
+ out << " = this.__isset." << get_isset_name(normalize_name((*m_iter)->get_name()));
+ out << (inline_assignment ? "," : ";") << endl;
}
}
+ if(inline_assignment) {
+ indent_down();
+ out << indent() << "};" << endl;
+ }
+
out << indent() << "return " << tmp_instance << ";" << endl;
indent_down();
@@ -1271,6 +1323,9 @@
if (fields.size() > 0)
{
tmpvar = tmp("tmp");
+ if(target_net_version >= 8) {
+ out << indent() << "#pragma warning disable IDE0017 // simplified init" << endl;
+ }
out << indent() << "var " << tmpvar << " = new TField();" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
{
@@ -1285,6 +1340,9 @@
out << indent() << "await oprot.WriteFieldEndAsync(" << CANCELLATION_TOKEN_NAME << ");" << endl;
generate_null_check_end(out, *f_iter);
}
+ if(target_net_version >= 8) {
+ out << indent() << "#pragma warning restore IDE0017 // simplified init" << endl;
+ }
}
out << indent() << "await oprot.WriteFieldStopAsync(" << CANCELLATION_TOKEN_NAME << ");" << endl
@@ -1323,6 +1381,9 @@
if (fields.size() > 0)
{
tmpvar = tmp("tmp");
+ if(target_net_version >= 8) {
+ out << indent() << "#pragma warning disable IDE0017 // simplified init" << endl;
+ }
out << indent() << "var " << tmpvar << " = new TField();" << endl;
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
@@ -1367,6 +1428,9 @@
indent_down();
out << indent() << "}" << endl;
}
+ if(target_net_version >= 8) {
+ out << indent() << "#pragma warning restore IDE0017 // simplified init" << endl;
+ }
}
out << indent() << "await oprot.WriteFieldStopAsync(" << CANCELLATION_TOKEN_NAME << ");" << endl
@@ -1481,7 +1545,7 @@
out << indent() << "public override bool Equals(object" << nullable_suffix() << " that)" << endl;
scope_up(out);
- if( use_net6_features) {
+ if( target_net_version >= 6) {
out << indent() << "if (that is not " << tunion->get_name() << " other) return false;" << endl;
} else {
out << indent() << "if (!(that is " << tunion->get_name() << " other)) return false;" << endl;
@@ -1490,7 +1554,7 @@
out << endl;
out << indent() << "if(this.Isset != other.Isset) return false;" << endl;
out << endl;
- if(use_net6_features) {
+ if(target_net_version >= 6) {
out << indent() << "return Isset switch" << endl;
scope_up(out);
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
@@ -1528,13 +1592,13 @@
out << indent() << "public override int GetHashCode()" << endl;
out << indent() << "{" << endl;
indent_up();
- if(use_net6_features) {
+ if(target_net_version >= 6) {
out << indent() << "return Isset switch" << endl;
out << indent() << "{" << endl;
indent_up();
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
{
- string null_coalesce(is_nullable_type((*f_iter)->get_type()) ? "?" : "");
+ string null_coalesce(is_nullable_type((*f_iter)->get_type()) ? "?" : "");
out << indent() << (*f_iter)->get_key() << " => As_" << (*f_iter)->get_name() << null_coalesce << ".GetHashCode()";
if( null_coalesce.size() > 0) {
out << " ?? 0";
@@ -1550,7 +1614,7 @@
indent_up();
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
{
- string null_coalesce(is_nullable_type((*f_iter)->get_type()) ? "?" : "");
+ string null_coalesce(is_nullable_type((*f_iter)->get_type()) ? "?" : "");
out << indent() << "case " << (*f_iter)->get_key() << ":" << endl;
indent_up();
out << indent() << "return As_" << (*f_iter)->get_name() << null_coalesce << ".GetHashCode()";
@@ -1574,7 +1638,7 @@
out << indent() << "public " << tunion->get_name() << " " << DEEP_COPY_METHOD_NAME << "()" << endl;
out << indent() << "{" << endl;
indent_up();
- if(use_net6_features) {
+ if(target_net_version >= 6) {
out << indent() << "return Isset switch" << endl;
out << indent() << "{" << endl;
indent_up();
@@ -1666,7 +1730,7 @@
out << indent() << "return (" << tfield->get_key() << " == Isset) && (Data != null)"
<< " ? (" << type_name(tfield->get_type()) << nullable_field_suffix(tfield) << ")Data"
<< " : default"
- << (use_net6_features ? "" : ("(" + type_name(tfield->get_type()) + ")"))
+ << (target_net_version >= 6 ? "" : ("(" + type_name(tfield->get_type()) + ")"))
<< ";" << endl;
indent_down();
out << indent() << "}" << endl;
@@ -1703,7 +1767,7 @@
out << indent() << "public override bool Equals(object" << nullable_suffix() << " that)" << endl;
out << indent() << "{" << endl;
indent_up();
- if(use_net6_features) {
+ if(target_net_version >= 6) {
out << indent() << "if (that is not " << tunion->get_name() << " other) return false;" << endl;
} else {
out << indent() << "if (!(that is " << tunion->get_name() << " other)) return false;" << endl;
@@ -1732,11 +1796,15 @@
out << indent() << "var struc = new TStruct(\"" << tunion->get_name() << "\");" << endl
<< indent() << "await oprot.WriteStructBeginAsync(struc, " << CANCELLATION_TOKEN_NAME << ");" << endl;
- out << indent() << "var field = new TField();" << endl
- << indent() << "field.Name = \"" << tfield->get_name() << "\";" << endl
- << indent() << "field.Type = " << type_to_enum(tfield->get_type()) << ";" << endl
- << indent() << "field.ID = " << tfield->get_key() << ";" << endl
- << indent() << "await oprot.WriteFieldBeginAsync(field, " << CANCELLATION_TOKEN_NAME << ");" << endl;
+ out << indent() << "var field = new TField()" << endl;
+ out << indent() << "{" << endl;
+ indent_up();
+ out << indent() << "Name = \"" << tfield->get_name() << "\"," << endl
+ << indent() << "Type = " << type_to_enum(tfield->get_type()) << "," << endl
+ << indent() << "ID = " << tfield->get_key() << endl;
+ indent_down();
+ out << indent() << "};" << endl;
+ out << indent() << "await oprot.WriteFieldBeginAsync(field, " << CANCELLATION_TOKEN_NAME << ");" << endl;
generate_serialize_field(out, tfield, "_data", true, false);
@@ -1762,7 +1830,7 @@
out << indent() << "public override bool Equals(object" << nullable_suffix() << " that)" << endl
<< indent() << "{" << endl;
indent_up();
- if(use_net6_features) {
+ if(target_net_version >= 6) {
out << indent() << "if (that is not " << type_name(tstruct,false) << " other) return false;" << endl;
} else {
out << indent() << "if (!(that is " << type_name(tstruct,false) << " other)) return false;" << endl;
@@ -2203,9 +2271,14 @@
if (extends.empty())
{
- out << indent() << "protected Dictionary<string, ProcessFunction> processMap_ = new"
- << (use_net6_features ? "" : " Dictionary<string, ProcessFunction>") // Simplify new expression (IDE0090)
- << "();" << endl;
+ out << indent() << "protected Dictionary<string, ProcessFunction> processMap_ = ";
+ if(target_net_version >= 8) {
+ out << "[];" << endl;
+ } else if(target_net_version >= 6) {
+ out << "new();" << endl;
+ } else {
+ out << "new Dictionary<string, ProcessFunction>();" << endl;
+ }
}
out << endl;
@@ -2960,7 +3033,7 @@
if (is_required)
{
out << " { get; set; }";
- if( use_net6_features && (!force_member_nullable(tfield))) {
+ if( (target_net_version >= 6) && (!force_member_nullable(tfield))) {
out << initialize_field(tfield) << ";";
}
out << endl;
@@ -3258,7 +3331,7 @@
string t_netstd_generator::nullable_suffix() {
- if(use_net6_features) {
+ if(target_net_version >= 6) {
return "?";
} else {
return "";
@@ -3272,10 +3345,10 @@
else
return nullable_field_suffix(tfield->get_type());
}
-
+
string t_netstd_generator::nullable_field_suffix(t_type* ttype) {
- if( ! use_net6_features) {
+ if( target_net_version < 6) {
return "";
}
@@ -3300,7 +3373,7 @@
}
string t_netstd_generator::nullable_value_access(t_type* ttype) {
- if( ! use_net6_features)
+ if( target_net_version < 6)
return "";
ttype = resolve_typedef(ttype);
@@ -3326,9 +3399,9 @@
}
bool t_netstd_generator::force_member_nullable(t_field* tfield) {
- // IMPORTANT:
+ // IMPORTANT:
// If tfield is a struct that contains a required field of the same type (directly or indirectly),
- // auto-initializing such a member field would immediately produce an OOM, or at least unexpectedly
+ // auto-initializing such a member field would immediately produce an OOM, or at least unexpectedly
// allocate potentially large amounts of memory -> ALWAYS leave containers and struct members nullable
t_type* ttype = resolve_typedef(tfield->get_type());
return ttype->is_struct() || ttype->is_container();
@@ -3427,12 +3500,15 @@
case t_base_type::TYPE_STRING:
if (ttype->is_binary()) {
suffix = nullable_suffix();
- if( use_net6_features) {
+ if( target_net_version >= 8) {
+ null_check = is_not_null ? "!" : " ?? []";
+ }
+ else if( target_net_version >= 6) {
null_check = is_not_null ? "!" : " ?? Array.Empty<byte>()";
}
return ".ToArray()" + null_check;
} else {
- if( use_net6_features) {
+ if( target_net_version >= 6) {
null_check = is_not_null ? "!" : " ?? string.Empty";
}
return null_check; // simple assignment will do, strings are immutable in C#
@@ -3448,23 +3524,25 @@
}
else if (is_union_enabled() && ttype->is_struct() && static_cast<t_struct*>(ttype)->is_union())
{
- needs_typecast = (! ttype->is_container());
+ needs_typecast = (! ttype->is_container());
suffix = nullable_suffix();
- if( use_net6_features) {
+ if( target_net_version >= 6) {
null_check = is_not_null ? "!" : " ?? new "+ttype->get_name() +".___undefined()";
- }
+ }
return "." + DEEP_COPY_METHOD_NAME + "()" + null_check;
}
else
{
- needs_typecast = (! ttype->is_container());
+ needs_typecast = (! ttype->is_container());
suffix = nullable_suffix();
- if( use_net6_features) {
+ if( (target_net_version >= 8) && ttype->is_container()) {
+ null_check = is_not_null ? "!" : " ?? []";
+ } else if( target_net_version >= 6) {
null_check = is_not_null ? "!" : " ?? new()";
- }
+ }
return "." + DEEP_COPY_METHOD_NAME + "()" + null_check;
}
-
+
throw "UNEXPECTED TYPE IN get_deep_copy_method_call: " + ttype->get_name();
}
@@ -3486,8 +3564,8 @@
string t_netstd_generator::initialize_field(t_field* tfield)
{
t_type* ttype = tfield->get_type();
- ttype = resolve_typedef(ttype);
-
+ ttype = resolve_typedef(ttype);
+
if (ttype->is_base_type() && field_has_default(tfield))
{
std::ofstream dummy;
@@ -3505,9 +3583,9 @@
case t_base_type::TYPE_VOID:
throw "NO T_VOID CONSTRUCT";
case t_base_type::TYPE_STRING:
- if(use_net6_features && field_is_required(tfield)) {
+ if((target_net_version >= 6) && field_is_required(tfield)) {
if (ttype->is_binary()) {
- return " = Array.Empty<byte>()";
+ return target_net_version >= 8 ? "= []" : " = Array.Empty<byte>()";
} else {
return " = string.Empty";
}
@@ -3538,7 +3616,7 @@
}
else if (ttype->is_container())
{
- if(use_net6_features) {
+ if(target_net_version >= 6) {
return " = new()";
} else {
return " = new " + type_name(ttype) + "()";
@@ -3546,8 +3624,8 @@
}
else if (ttype->is_struct())
{
- t_struct* tstruct = static_cast<t_struct*>(ttype);
- if(use_net6_features) {
+ t_struct* tstruct = static_cast<t_struct*>(ttype);
+ if(target_net_version >= 6) {
if(tstruct->is_union()) {
return " = new " + type_name(ttype) + ".___undefined()";
} else {
@@ -3557,7 +3635,7 @@
return " = new " + type_name(ttype) + "()";
}
}
-
+
throw "UNEXPECTED TYPE IN initialize_field: " + ttype->get_name();
}
@@ -3777,6 +3855,7 @@
" union: Use new union typing, which includes a static read function for union types.\n"
" pascal: Generate Pascal Case property names according to Microsoft naming convention.\n"
" net6: Enable features that require net6 and C# 8 or higher.\n"
+ " net8: Enable features that require net8 and C# 12 or higher.\n"
" no_deepcopy: Suppress generation of " + DEEP_COPY_METHOD_NAME + "() method.\n"
" async_postfix: Append \"Async\" to all service methods (maintains compatibility with existing code).\n"
)
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.h b/compiler/cpp/src/thrift/generate/t_netstd_generator.h
index f16f7d3..ff3cfb1 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.h
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.h
@@ -154,12 +154,12 @@
protected:
std::string autogen_comment() override {
string comment = "/**\n";
- if( ! use_net6_features) {
+ if( target_net_version < 6) {
comment += " * <auto-generated>\n";
}
comment += " * " + autogen_summary() + "\n";
comment += " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n";
- if( ! use_net6_features) {
+ if( target_net_version < 6) {
comment += " * </auto-generated>\n";
}
comment += " */\n";
@@ -177,7 +177,7 @@
bool wcf_;
bool use_pascal_case_properties;
bool suppress_deepcopy;
- bool use_net6_features;
+ int target_net_version; // 0 = any, 6 = net6, 8 = net8
bool add_async_postfix;
const std::string CSHARP_KEYWORDS[101] = {
diff --git a/lib/netstd/Benchmarks/Thrift.Benchmarks/Thrift.Benchmarks.csproj b/lib/netstd/Benchmarks/Thrift.Benchmarks/Thrift.Benchmarks.csproj
index b5afef5..cc2360d 100644
--- a/lib/netstd/Benchmarks/Thrift.Benchmarks/Thrift.Benchmarks.csproj
+++ b/lib/netstd/Benchmarks/Thrift.Benchmarks/Thrift.Benchmarks.csproj
@@ -20,7 +20,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<TieredCompilation>false</TieredCompilation>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Nullable>enable</Nullable>
diff --git a/lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj b/lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj
index 98e8007..3f52a5f 100644
--- a/lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj
+++ b/lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj
@@ -19,7 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<AssemblyName>Thrift.IntegrationTests</AssemblyName>
<PackageId>Thrift.IntegrationTests</PackageId>
<Version>0.20.0.0</Version>
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
index 6f3abb1..ecde366 100644
--- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
@@ -21,7 +21,8 @@
<PropertyGroup>
<ThriftVersion>0.20.0</ThriftVersion>
<ThriftVersionOutput>Thrift version $(ThriftVersion)</ThriftVersionOutput>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<Version>$(ThriftVersion).0</Version>
<AssemblyName>Thrift.PublicInterfaces.Compile.Tests</AssemblyName>
<PackageId>Thrift.PublicInterfaces.Compile.Tests</PackageId>
@@ -68,14 +69,14 @@
<Error Condition="$('$(ThriftBinaryVersion)'::StartsWith('$(ThriftVersionOutput)')) == true" Text="Thrift version returned: '$(ThriftBinaryVersion)' is not equal to the projects version '$(ThriftVersionOutput)'." />
<Message Importance="high" Text="Generating tests with thrift binary: '$(PathToThrift)'" />
<!-- Generate the thrift test files -->
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./CassandraTest.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./optional_required_default.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./name_conflicts.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./../../../../test/ThriftTest.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./../../../../contrib/fb303/if/fb303.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./Thrift5253.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./Thrift5320.thrift" />
- <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net6 -r ./Thrift5382.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./CassandraTest.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./optional_required_default.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./name_conflicts.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./../../../../test/ThriftTest.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./../../../../contrib/fb303/if/fb303.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5253.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5320.thrift" />
+ <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5382.thrift" />
</Target>
</Project>
diff --git a/lib/netstd/Tests/Thrift.Tests/Collections/TCollectionsTests.cs b/lib/netstd/Tests/Thrift.Tests/Collections/TCollectionsTests.cs
index 49108d1..c6cd22d 100644
--- a/lib/netstd/Tests/Thrift.Tests/Collections/TCollectionsTests.cs
+++ b/lib/netstd/Tests/Thrift.Tests/Collections/TCollectionsTests.cs
@@ -56,8 +56,8 @@
[TestMethod]
public void TCollection_List_Equals_Objects_Test()
{
- var collection1 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
- var collection2 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
+ var collection1 = new List<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
+ var collection2 = new List<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsTrue(collection1.SequenceEqual(collection2));
}
@@ -65,8 +65,8 @@
[TestMethod]
public void TCollection_List_List_Equals_Objects_Test()
{
- var collection1 = new List<List<ExampleClass>> { new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } } };
- var collection2 = new List<List<ExampleClass>> { new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } } };
+ var collection1 = new List<List<ExampleClass>> { new() { new() { X = 1 }, new() { X = 2 } } };
+ var collection2 = new List<List<ExampleClass>> { new() { new() { X = 1 }, new() { X = 2 } } };
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsFalse(collection1.SequenceEqual(collection2)); // SequenceEqual() calls Equals() of the inner list instead of SequenceEqual()
}
@@ -74,7 +74,7 @@
[TestMethod]
public void TCollection_List_Equals_OneAndTheSameObject_Test()
{
- var collection1 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
+ var collection1 = new List<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
var collection2 = collection1;
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsTrue(collection1.SequenceEqual(collection2));
@@ -105,8 +105,8 @@
[TestMethod]
public void TCollection_Set_Equals_Objects_Test()
{
- var collection1 = new HashSet<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
- var collection2 = new HashSet<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
+ var collection1 = new HashSet<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
+ var collection2 = new HashSet<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsTrue(collection1.SequenceEqual(collection2));
}
@@ -114,8 +114,8 @@
[TestMethod]
public void TCollection_Set_Set_Equals_Objects_Test()
{
- var collection1 = new HashSet<HashSet<ExampleClass>> { new HashSet<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } } };
- var collection2 = new HashSet<HashSet<ExampleClass>> { new HashSet<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } } };
+ var collection1 = new HashSet<HashSet<ExampleClass>> { new() { new() { X = 1 }, new() { X = 2 } } };
+ var collection2 = new HashSet<HashSet<ExampleClass>> { new() { new() { X = 1 }, new() { X = 2 } } };
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsFalse(collection1.SequenceEqual(collection2)); // SequenceEqual() calls Equals() of the inner list instead of SequenceEqual()
}
@@ -123,7 +123,7 @@
[TestMethod]
public void TCollection_Set_Equals_OneAndTheSameObject_Test()
{
- var collection1 = new HashSet<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } };
+ var collection1 = new HashSet<ExampleClass> { new() { X = 1 }, new() { X = 2 } };
var collection2 = collection1; // references to one and the same collection
Assert.IsTrue(TCollections.Equals(collection1, collection2));
Assert.IsTrue(collection1.SequenceEqual(collection2));
@@ -160,13 +160,13 @@
{
var collection1 = new Dictionary<int, ExampleClass>
{
- [1] = new ExampleClass { X = 1 },
- [-1] = new ExampleClass { X = 2 }
+ [1] = new() { X = 1 },
+ [-1] = new() { X = 2 }
};
var collection2 = new Dictionary<int, ExampleClass>
{
- [1] = new ExampleClass { X = 1 },
- [-1] = new ExampleClass { X = 2 }
+ [1] = new() { X = 1 },
+ [-1] = new() { X = 2 }
};
Assert.IsTrue(TCollections.Equals(collection1, collection2));
@@ -180,16 +180,16 @@
{
[0] = new Dictionary<int, ExampleClass>
{
- [1] = new ExampleClass { X = 1 },
- [-1] = new ExampleClass { X = 2 }
+ [1] = new() { X = 1 },
+ [-1] = new() { X = 2 }
}
};
var collection2 = new Dictionary<int, Dictionary<int, ExampleClass>>
{
[0] = new Dictionary<int, ExampleClass>
{
- [1] = new ExampleClass { X = 1 },
- [-1] = new ExampleClass { X = 2 }
+ [1] = new() { X = 1 },
+ [-1] = new() { X = 2 }
}
};
@@ -202,8 +202,8 @@
{
var collection1 = new Dictionary<int, ExampleClass>
{
- [1] = new ExampleClass { X = 1 },
- [-1] = new ExampleClass { X = 2 }
+ [1] = new() { X = 1 },
+ [-1] = new() { X = 2 }
};
var collection2 = collection1;
Assert.IsTrue(TCollections.Equals(collection1, collection2));
diff --git a/lib/netstd/Tests/Thrift.Tests/DataModel/DeepCopy.cs b/lib/netstd/Tests/Thrift.Tests/DataModel/DeepCopy.cs
index 11b5af4..7a43ca8 100644
--- a/lib/netstd/Tests/Thrift.Tests/DataModel/DeepCopy.cs
+++ b/lib/netstd/Tests/Thrift.Tests/DataModel/DeepCopy.cs
@@ -59,7 +59,7 @@
return instance;
}
- private jack? MakeNestedUnion(int nesting)
+ private jack.nested_struct? MakeNestedUnion(int nesting)
{
if (++nesting > 1)
return null;
@@ -148,14 +148,14 @@
if (nesting < 2)
{
- instance.Far_list = new List<Distance>() { Distance.foo, Distance.bar, Distance.baz };
- instance.Far_set = new HashSet<Distance>() { Distance.foo, Distance.bar, Distance.baz };
- instance.Far_map = new Dictionary<Distance, Distance>() { [Distance.foo] = Distance.foo, [Distance.bar] = Distance.bar, [Distance.baz] = Distance.baz };
+ instance.Far_list = [Distance.foo, Distance.bar, Distance.baz];
+ instance.Far_set = [Distance.foo, Distance.bar, Distance.baz];
+ instance.Far_map = new() { [Distance.foo] = Distance.foo, [Distance.bar] = Distance.bar, [Distance.baz] = Distance.baz };
- instance.Far_set_list = new HashSet<List<Distance>>() { new List<Distance>() { Distance.foo } };
- instance.Far_list_map_set = new List<Dictionary<sbyte, HashSet<Distance>>>() { new Dictionary<sbyte, HashSet<Distance>>() { [1] = new HashSet<Distance>() { Distance.baz } } };
+ instance.Far_set_list = [[Distance.foo]];
+ instance.Far_list_map_set = [new Dictionary<sbyte, HashSet<Distance>>() { [1] = [Distance.baz] }];
- instance.Far_map_dist_to_rds = new Dictionary<Distance, List<RaceDetails>>() { [Distance.bar] = new List<RaceDetails>() };
+ instance.Far_map_dist_to_rds = new() { [Distance.bar] = [] };
var details = MakeNestedRaceDetails(nesting);
if (details != null)
instance.Far_map_dist_to_rds[Distance.bar].Add(details);
@@ -265,8 +265,7 @@
if (++level > 4)
return value;
- if (value == null)
- value = MakeNestedUnion(0);
+ value ??= MakeNestedUnion(0);
Debug.Assert(value?.As_nested_struct != null);
ModifyInstance(value.As_nested_struct, level);
return value;
@@ -277,23 +276,21 @@
if (++level > 4)
return value;
- if (value == null)
- value = new RaceDetails();
+ value ??= new RaceDetails();
ModifyInstance(value,level);
return value;
}
private Dictionary<Distance, List<RaceDetails>> ModifyValue(Dictionary<Distance, List<RaceDetails>>? value, int level)
{
- if (value == null)
- value = new Dictionary<Distance, List<RaceDetails>>();
+ value ??= [];
if (++level > 4)
return value;
var details = new RaceDetails();
InitializeInstance(details);
- value[Distance.foo] = new List<RaceDetails>() { details };
+ value[Distance.foo] = [details];
if (value.TryGetValue(Distance.bar, out var list) && (list.Count > 0))
{
@@ -309,17 +306,16 @@
private static List<Dictionary<sbyte, HashSet<Distance>>> ModifyValue(List<Dictionary<sbyte, HashSet<Distance>>>? value)
{
- if (value == null)
- value = new List<Dictionary<sbyte, HashSet<Distance>>>();
+ value ??= [];
if (value.Count == 0)
- value.Add(new Dictionary<sbyte, HashSet<Distance>>());
+ value.Add([]);
//else
//value.Add(null); --Thrift does not allow null values in containers
sbyte key = (sbyte)(value[0].Count + 10);
if (value[0].Count == 0)
- value[0].Add(key, new HashSet<Distance>());
+ value[0].Add(key, []);
//else
//value[0].Add(key, null); --Thrift does not allow null values in containers
@@ -331,9 +327,7 @@
{
if (pair.Value != null)
{
- if (pair.Value.Contains(Distance.baz))
- pair.Value.Remove(Distance.baz);
- else
+ if (!pair.Value.Remove(Distance.baz))
pair.Value.Add(Distance.baz);
}
}
@@ -345,25 +339,22 @@
private static HashSet<List<Distance>> ModifyValue(HashSet<List<Distance>>? value)
{
- if (value == null)
- value = new HashSet<List<Distance>>();
+ value ??= [];
if (value.Count == 0)
- value.Add(new List<Distance>());
+ value.Add([]);
//else
//value.Add(null); -- Thrift does not allow null values in containers
foreach (var entry in value)
- if( entry != null)
- entry.Add(Distance.baz);
+ entry?.Add(Distance.baz);
return value;
}
private static Dictionary<Distance, Distance> ModifyValue(Dictionary<Distance, Distance>? value)
{
- if (value == null)
- value = new Dictionary<Distance, Distance>();
+ value ??= [];
value[Distance.foo] = value.ContainsKey(Distance.foo) ? ++value[Distance.foo] : Distance.foo;
value[Distance.bar] = value.ContainsKey(Distance.bar) ? ++value[Distance.bar] : Distance.bar;
value[Distance.baz] = value.ContainsKey(Distance.baz) ? ++value[Distance.baz] : Distance.baz;
@@ -372,22 +363,15 @@
private static HashSet<Distance> ModifyValue(HashSet<Distance>? value)
{
- if (value == null)
- value = new HashSet<Distance>();
+ value ??= [];
- if (value.Contains(Distance.foo))
- value.Remove(Distance.foo);
- else
+ if (!value.Remove(Distance.foo))
value.Add(Distance.foo);
- if (value.Contains(Distance.bar))
- value.Remove(Distance.bar);
- else
+ if (!value.Remove(Distance.bar))
value.Add(Distance.bar);
- if (value.Contains(Distance.baz))
- value.Remove(Distance.baz);
- else
+ if (!value.Remove(Distance.baz))
value.Add(Distance.baz);
return value;
@@ -395,8 +379,7 @@
private static List<Distance> ModifyValue(List<Distance>? value)
{
- if (value == null)
- value = new List<Distance>();
+ value ??= [];
value.Add(Distance.foo);
value.Add(Distance.bar);
value.Add(Distance.baz);
@@ -410,36 +393,32 @@
private static Dictionary<sbyte, short> ModifyValue(Dictionary<sbyte, short>? value)
{
- if (value == null)
- value = new Dictionary<sbyte, short>();
+ value ??= [];
value.Add((sbyte)(value.Count + 10), (short)value.Count);
return value;
}
private static HashSet<long> ModifyValue(HashSet<long>? value)
{
- if (value == null)
- value = new HashSet<long>();
+ value ??= [];
value.Add(value.Count+100);
return value;
}
private static List<int> ModifyValue(List<int>? value)
{
- if (value == null)
- value = new List<int>();
+ value ??= [];
value.Add(value.Count);
return value;
}
private static byte[] ModifyValue(byte[]? value)
{
- if (value == null)
- value = new byte[1] { 0 };
+ value ??= [0];
if (value.Length > 0)
value[0] = (value[0] < 0xFF) ? ++value[0] : (byte)0;
else
- value = new byte[1] { 0 };
+ value = [0];
return value;
}
diff --git a/lib/netstd/Tests/Thrift.Tests/DataModel/NullValuesSet.cs b/lib/netstd/Tests/Thrift.Tests/DataModel/NullValuesSet.cs
index 80eacc2..09f7251 100644
--- a/lib/netstd/Tests/Thrift.Tests/DataModel/NullValuesSet.cs
+++ b/lib/netstd/Tests/Thrift.Tests/DataModel/NullValuesSet.cs
@@ -25,6 +25,7 @@
using OptReqDefTest;
using Thrift.Collections;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
#pragma warning disable IDE0017 // init can be simplified - we don't want that here
namespace Thrift.Tests.DataModel
diff --git a/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolHelperTests.cs b/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolHelperTests.cs
index 6d39151..03e3efa 100644
--- a/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolHelperTests.cs
+++ b/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolHelperTests.cs
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation(ASF) under one
+// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.The ASF licenses this file
@@ -34,17 +34,17 @@
// input/output
var sets = new List<Tuple<TType, byte[]>>
{
- new Tuple<TType, byte[]>(TType.Bool, TJSONProtocolConstants.TypeNames.NameBool),
- new Tuple<TType, byte[]>(TType.Byte, TJSONProtocolConstants.TypeNames.NameByte),
- new Tuple<TType, byte[]>(TType.I16, TJSONProtocolConstants.TypeNames.NameI16),
- new Tuple<TType, byte[]>(TType.I32, TJSONProtocolConstants.TypeNames.NameI32),
- new Tuple<TType, byte[]>(TType.I64, TJSONProtocolConstants.TypeNames.NameI64),
- new Tuple<TType, byte[]>(TType.Double, TJSONProtocolConstants.TypeNames.NameDouble),
- new Tuple<TType, byte[]>(TType.String, TJSONProtocolConstants.TypeNames.NameString),
- new Tuple<TType, byte[]>(TType.Struct, TJSONProtocolConstants.TypeNames.NameStruct),
- new Tuple<TType, byte[]>(TType.Map, TJSONProtocolConstants.TypeNames.NameMap),
- new Tuple<TType, byte[]>(TType.Set, TJSONProtocolConstants.TypeNames.NameSet),
- new Tuple<TType, byte[]>(TType.List, TJSONProtocolConstants.TypeNames.NameList),
+ new(TType.Bool, TJSONProtocolConstants.TypeNames.NameBool),
+ new(TType.Byte, TJSONProtocolConstants.TypeNames.NameByte),
+ new(TType.I16, TJSONProtocolConstants.TypeNames.NameI16),
+ new(TType.I32, TJSONProtocolConstants.TypeNames.NameI32),
+ new(TType.I64, TJSONProtocolConstants.TypeNames.NameI64),
+ new(TType.Double, TJSONProtocolConstants.TypeNames.NameDouble),
+ new(TType.String, TJSONProtocolConstants.TypeNames.NameString),
+ new(TType.Struct, TJSONProtocolConstants.TypeNames.NameStruct),
+ new(TType.Map, TJSONProtocolConstants.TypeNames.NameMap),
+ new(TType.Set, TJSONProtocolConstants.TypeNames.NameSet),
+ new(TType.List, TJSONProtocolConstants.TypeNames.NameList),
};
foreach (var t in sets)
@@ -73,17 +73,17 @@
// input/output
var sets = new List<Tuple<TType, byte[]>>
{
- new Tuple<TType, byte[]>(TType.Bool, TJSONProtocolConstants.TypeNames.NameBool),
- new Tuple<TType, byte[]>(TType.Byte, TJSONProtocolConstants.TypeNames.NameByte),
- new Tuple<TType, byte[]>(TType.I16, TJSONProtocolConstants.TypeNames.NameI16),
- new Tuple<TType, byte[]>(TType.I32, TJSONProtocolConstants.TypeNames.NameI32),
- new Tuple<TType, byte[]>(TType.I64, TJSONProtocolConstants.TypeNames.NameI64),
- new Tuple<TType, byte[]>(TType.Double, TJSONProtocolConstants.TypeNames.NameDouble),
- new Tuple<TType, byte[]>(TType.String, TJSONProtocolConstants.TypeNames.NameString),
- new Tuple<TType, byte[]>(TType.Struct, TJSONProtocolConstants.TypeNames.NameStruct),
- new Tuple<TType, byte[]>(TType.Map, TJSONProtocolConstants.TypeNames.NameMap),
- new Tuple<TType, byte[]>(TType.Set, TJSONProtocolConstants.TypeNames.NameSet),
- new Tuple<TType, byte[]>(TType.List, TJSONProtocolConstants.TypeNames.NameList),
+ new(TType.Bool, TJSONProtocolConstants.TypeNames.NameBool),
+ new(TType.Byte, TJSONProtocolConstants.TypeNames.NameByte),
+ new(TType.I16, TJSONProtocolConstants.TypeNames.NameI16),
+ new(TType.I32, TJSONProtocolConstants.TypeNames.NameI32),
+ new(TType.I64, TJSONProtocolConstants.TypeNames.NameI64),
+ new(TType.Double, TJSONProtocolConstants.TypeNames.NameDouble),
+ new(TType.String, TJSONProtocolConstants.TypeNames.NameString),
+ new(TType.Struct, TJSONProtocolConstants.TypeNames.NameStruct),
+ new(TType.Map, TJSONProtocolConstants.TypeNames.NameMap),
+ new(TType.Set, TJSONProtocolConstants.TypeNames.NameSet),
+ new(TType.List, TJSONProtocolConstants.TypeNames.NameList),
};
foreach (var t in sets)
@@ -96,21 +96,21 @@
[ExpectedException(typeof(TProtocolException))]
public void GetTypeIdForTypeName_TStopTypeName_Test()
{
- TJSONProtocolHelper.GetTypeIdForTypeName(new []{(byte)TType.Stop, (byte)TType.Stop});
+ TJSONProtocolHelper.GetTypeIdForTypeName([(byte)TType.Stop, (byte)TType.Stop]);
}
[TestMethod]
[ExpectedException(typeof(TProtocolException))]
public void GetTypeIdForTypeName_NonExistingTypeName_Test()
{
- TJSONProtocolHelper.GetTypeIdForTypeName(new byte[]{100});
+ TJSONProtocolHelper.GetTypeIdForTypeName([100]);
}
[TestMethod]
[ExpectedException(typeof(TProtocolException))]
public void GetTypeIdForTypeName_EmptyName_Test()
{
- TJSONProtocolHelper.GetTypeIdForTypeName(new byte[] {});
+ TJSONProtocolHelper.GetTypeIdForTypeName([]);
}
[TestMethod]
@@ -169,4 +169,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolTests.cs b/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolTests.cs
index 4054a29..4f14ba7 100644
--- a/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolTests.cs
+++ b/lib/netstd/Tests/Thrift.Tests/Protocols/TJsonProtocolTests.cs
@@ -51,12 +51,8 @@
Assert.IsTrue(result.WrappedReader.GetType().Name.Equals("LookaheadReader", StringComparison.OrdinalIgnoreCase));
}
- private class TJSONProtocolWrapper : TJsonProtocol
+ private class TJSONProtocolWrapper(TTransport trans) : TJsonProtocol(trans)
{
- public TJSONProtocolWrapper(TTransport trans) : base(trans)
- {
- }
-
public object WrappedContext => Context;
public object WrappedReader => Reader;
public int WrappedRecursionDepth => RecursionDepth;
diff --git a/lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj b/lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj
index 94b7b09..54ce1e8 100644
--- a/lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj
+++ b/lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj
@@ -19,7 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<Version>0.20.0.0</Version>
<Nullable>enable</Nullable>
</PropertyGroup>
diff --git a/lib/netstd/Thrift/.editorconfig b/lib/netstd/Thrift/.editorconfig
index 54b698c..82ff4a3 100644
--- a/lib/netstd/Thrift/.editorconfig
+++ b/lib/netstd/Thrift/.editorconfig
@@ -2,3 +2,8 @@
# CS1591: missing XML comment for public element
dotnet_diagnostic.CS1591.severity = silent
+
+# silence certain yet unfixed false positives for net8
+dotnet_diagnostic.IDE0290.severity = silent
+dotnet_diagnostic.CA1510.severity = silent
+dotnet_diagnostic.CA1513.severity = silent
diff --git a/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs b/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs
index 9759058..5fc1fda 100644
--- a/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs
+++ b/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs
@@ -23,6 +23,11 @@
using Thrift.Protocol;
using Thrift.Protocol.Entities;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0028 // net8 - simplified collection init
+#pragma warning disable IDE0300 // net8 - simplified collection init
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Processor
{
// ReSharper disable once InconsistentNaming
@@ -30,8 +35,7 @@
{
//TODO: Localization
- private readonly Dictionary<string, ITAsyncProcessor> _serviceProcessorMap =
- new Dictionary<string, ITAsyncProcessor>();
+ private readonly Dictionary<string, ITAsyncProcessor> _serviceProcessorMap = new Dictionary<string, ITAsyncProcessor>();
public async Task<bool> ProcessAsync(TProtocol iprot, TProtocol oprot)
{
diff --git a/lib/netstd/Thrift/Processor/TSingletonProcessorFactory.cs b/lib/netstd/Thrift/Processor/TSingletonProcessorFactory.cs
index 97ecff6..568a50c 100644
--- a/lib/netstd/Thrift/Processor/TSingletonProcessorFactory.cs
+++ b/lib/netstd/Thrift/Processor/TSingletonProcessorFactory.cs
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation(ASF) under one
+// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.The ASF licenses this file
@@ -18,6 +18,9 @@
using Thrift.Server;
using Thrift.Transport;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Processor
{
// ReSharper disable once InconsistentNaming
@@ -35,4 +38,4 @@
return _asyncProcessor;
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TField.cs b/lib/netstd/Thrift/Protocol/Entities/TField.cs
index 4e29bb5..92fd41a 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TField.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TField.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
@@ -34,4 +37,4 @@
// ReSharper disable once InconsistentNaming - do not rename - it used for generation
public short ID { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TList.cs b/lib/netstd/Thrift/Protocol/Entities/TList.cs
index f599225..7e5c545 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TList.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TList.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
@@ -30,4 +33,4 @@
public int Count { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TMap.cs b/lib/netstd/Thrift/Protocol/Entities/TMap.cs
index 1efebe7..fba5780 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TMap.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TMap.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
@@ -33,4 +36,4 @@
public int Count { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TMessage.cs b/lib/netstd/Thrift/Protocol/Entities/TMessage.cs
index 08d741d..2e586ea 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TMessage.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TMessage.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
@@ -34,4 +37,4 @@
// ReSharper disable once InconsistentNaming - do not rename - it used for generation
public int SeqID { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TSet.cs b/lib/netstd/Thrift/Protocol/Entities/TSet.cs
index 692d564..d29cc0d 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TSet.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TSet.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
@@ -35,4 +38,4 @@
public int Count { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Entities/TStruct.cs b/lib/netstd/Thrift/Protocol/Entities/TStruct.cs
index d876087..b2fd000 100644
--- a/lib/netstd/Thrift/Protocol/Entities/TStruct.cs
+++ b/lib/netstd/Thrift/Protocol/Entities/TStruct.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol.Entities
{
// ReSharper disable once InconsistentNaming
diff --git a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
index 7feb698..6389184 100644
--- a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
@@ -24,6 +24,8 @@
using Thrift.Protocol.Utilities;
using Thrift.Transport;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
namespace Thrift.Protocol
{
@@ -33,8 +35,8 @@
protected const uint VersionMask = 0xffff0000;
protected const uint Version1 = 0x80010000;
- protected bool StrictRead;
- protected bool StrictWrite;
+ protected readonly bool StrictRead;
+ protected readonly bool StrictWrite;
// minimize memory allocations by means of an preallocated bytes buffer
// The value of 128 is arbitrarily chosen, the required minimum size must be sizeof(long)
@@ -470,15 +472,10 @@
public class Factory : TProtocolFactory
{
- protected bool StrictRead;
- protected bool StrictWrite;
+ protected readonly bool StrictRead;
+ protected readonly bool StrictWrite;
- public Factory()
- : this(false, true)
- {
- }
-
- public Factory(bool strictRead, bool strictWrite)
+ public Factory(bool strictRead = false, bool strictWrite = true)
{
StrictRead = strictRead;
StrictWrite = strictWrite;
diff --git a/lib/netstd/Thrift/Protocol/TCompactProtocol.cs b/lib/netstd/Thrift/Protocol/TCompactProtocol.cs
index dd38f48..8e5d00d 100644
--- a/lib/netstd/Thrift/Protocol/TCompactProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TCompactProtocol.cs
@@ -27,6 +27,8 @@
using Thrift.Protocol.Utilities;
using Thrift.Transport;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0301 // net8 - simplified collection init
namespace Thrift.Protocol
{
diff --git a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
index 9f761ae..64308d6 100644
--- a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
@@ -27,6 +27,8 @@
using Thrift.Protocol.Utilities;
using Thrift.Transport;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
namespace Thrift.Protocol
{
diff --git a/lib/netstd/Thrift/Protocol/TMultiplexedProtocol.cs b/lib/netstd/Thrift/Protocol/TMultiplexedProtocol.cs
index fbc8c05..510dc28 100644
--- a/lib/netstd/Thrift/Protocol/TMultiplexedProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TMultiplexedProtocol.cs
@@ -19,6 +19,9 @@
using System.Threading.Tasks;
using Thrift.Protocol.Entities;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Protocol
{
/**
diff --git a/lib/netstd/Thrift/Protocol/ToString.cs b/lib/netstd/Thrift/Protocol/ToString.cs
index ae69d1c..9a94c08 100644
--- a/lib/netstd/Thrift/Protocol/ToString.cs
+++ b/lib/netstd/Thrift/Protocol/ToString.cs
@@ -34,16 +34,16 @@
sb.Append(", ");
bool first_child = true;
- if (self is string) // string is IEnumerable
+ if (self is string str) // string is IEnumerable
{
sb.Append('"');
- sb.Append(self);
+ sb.Append(str);
sb.Append('"');
}
- else if (self is IDictionary)
+ else if (self is IDictionary dict)
{
sb.Append("{ ");
- foreach (DictionaryEntry pair in (self as IDictionary))
+ foreach (DictionaryEntry pair in dict)
{
if (first_child)
first_child = false;
@@ -58,23 +58,23 @@
}
sb.Append('}');
}
- else if (self is IEnumerable)
+ else if (self is IEnumerable enumerable)
{
sb.Append("{ ");
- foreach (var elm in (self as IEnumerable))
+ foreach (var elm in enumerable)
{
elm.ToString(sb, first_child);
first_child = false;
}
sb.Append('}');
}
- else if (self is TBase)
+ else if (self is TBase tbase)
{
- sb.Append((self as TBase).ToString());
+ sb.Append(tbase.ToString());
}
- else if (self is double)
+ else if (self is double dbVal)
{
- sb.Append(((double)self).ToString(CultureInfo.InvariantCulture));
+ sb.Append(dbVal.ToString(CultureInfo.InvariantCulture));
}
else
{
diff --git a/lib/netstd/Thrift/Protocol/Utilities/TBase64Utils.cs b/lib/netstd/Thrift/Protocol/Utilities/TBase64Utils.cs
index 90b8f88..15ef04f 100644
--- a/lib/netstd/Thrift/Protocol/Utilities/TBase64Utils.cs
+++ b/lib/netstd/Thrift/Protocol/Utilities/TBase64Utils.cs
@@ -17,6 +17,12 @@
using System;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0300 // net8 - simplified collection init
+#pragma warning disable IDE0028 // net8 - simplified collection init
+#pragma warning disable CA1510 // net8 - use ThrowIfNull
+#pragma warning disable CA1513 // net8 - use ThrowIfNull
+
namespace Thrift.Protocol.Utilities
{
// ReSharper disable once InconsistentNaming
@@ -98,4 +104,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/netstd/Thrift/Protocol/Utilities/TGuidExtensions.cs b/lib/netstd/Thrift/Protocol/Utilities/TGuidExtensions.cs
index 190ddbb..ecc0263 100644
--- a/lib/netstd/Thrift/Protocol/Utilities/TGuidExtensions.cs
+++ b/lib/netstd/Thrift/Protocol/Utilities/TGuidExtensions.cs
@@ -42,9 +42,7 @@
private static void SwapBytes(ref byte one, ref byte two)
{
- var tmp = one;
- one = two;
- two = tmp;
+ (two, one) = (one, two);
}
#region SelfTest
diff --git a/lib/netstd/Thrift/Protocol/Utilities/TJsonProtocolConstants.cs b/lib/netstd/Thrift/Protocol/Utilities/TJsonProtocolConstants.cs
index f8c261a..6e248db 100644
--- a/lib/netstd/Thrift/Protocol/Utilities/TJsonProtocolConstants.cs
+++ b/lib/netstd/Thrift/Protocol/Utilities/TJsonProtocolConstants.cs
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0300 // net8 - simplified collection init
+
namespace Thrift.Protocol.Utilities
{
// ReSharper disable once InconsistentNaming
diff --git a/lib/netstd/Thrift/Server/TServer.cs b/lib/netstd/Thrift/Server/TServer.cs
index 3d4f3fc..5f5bc49 100644
--- a/lib/netstd/Thrift/Server/TServer.cs
+++ b/lib/netstd/Thrift/Server/TServer.cs
@@ -65,8 +65,7 @@
// Log delegation? deprecated, use ILogger
protected void LogError( string msg)
{
- if (Logger != null)
- Logger.LogError("{Msg}",msg); // NOTE: Log message template, not string interpolation!
+ Logger?.LogError("{Msg}",msg); // NOTE: Log message template, not string interpolation!
}
public abstract void Stop();
diff --git a/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs b/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs
index f1f6277..ffa3b88 100644
--- a/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs
+++ b/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs
@@ -23,6 +23,8 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
namespace Thrift.Server
{
diff --git a/lib/netstd/Thrift/Thrift.csproj b/lib/netstd/Thrift/Thrift.csproj
index 2ebfb06..c7b2a82 100644
--- a/lib/netstd/Thrift/Thrift.csproj
+++ b/lib/netstd/Thrift/Thrift.csproj
@@ -19,7 +19,7 @@
-->
<PropertyGroup>
- <TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0</TargetFrameworks>
+ <TargetFrameworks>netstandard2.1;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<AssemblyName>Thrift</AssemblyName>
<PackageId>ApacheThrift</PackageId>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
diff --git a/lib/netstd/Thrift/Transport/Client/TTlsSocketTransport.cs b/lib/netstd/Thrift/Transport/Client/TTlsSocketTransport.cs
index bda1290..0a51c9a 100644
--- a/lib/netstd/Thrift/Transport/Client/TTlsSocketTransport.cs
+++ b/lib/netstd/Thrift/Transport/Client/TTlsSocketTransport.cs
@@ -25,6 +25,9 @@
using System.Threading;
using System.Threading.Tasks;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0028 // net8 - simplified collection init
+
namespace Thrift.Transport.Client
{
//TODO: check for correct work
diff --git a/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs b/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs
index 694ea0f..5e67f10 100644
--- a/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs
+++ b/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs
@@ -21,6 +21,10 @@
using System.Threading;
using System.Threading.Tasks;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable CA1510 // net8 - use ThrowIfNull
+#pragma warning disable CA1513 // net8 - use ThrowIfNull
+
namespace Thrift.Transport
{
// ReSharper disable once InconsistentNaming
diff --git a/lib/netstd/Thrift/Transport/Layered/TLayeredTransport.cs b/lib/netstd/Thrift/Transport/Layered/TLayeredTransport.cs
index 98fbd22..3d855a4 100644
--- a/lib/netstd/Thrift/Transport/Layered/TLayeredTransport.cs
+++ b/lib/netstd/Thrift/Transport/Layered/TLayeredTransport.cs
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation(ASF) under one
+// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.The ASF licenses this file
@@ -16,8 +16,9 @@
// under the License.
using System;
-using System.Collections.Generic;
-using System.Text;
+
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
namespace Thrift.Transport
{
diff --git a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
index b1ed91e..138c7fd 100644
--- a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
@@ -28,6 +28,11 @@
using System.IO;
using System.Diagnostics;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0028 // net8 - simplified collection init
+#pragma warning disable IDE0300 // net8 - simplified collection init
+#pragma warning disable IDE0290 // net8 - primary CTOR
+#pragma warning disable SYSLIB1054 // net8 - use LibraryImport attribute
#pragma warning disable CS1998 // async no await
namespace Thrift.Transport.Server
@@ -46,7 +51,7 @@
// to manage incoming connections, we set up a task for each stream to listen on
private struct TaskStreamPair
{
- public NamedPipeServerStream Stream;
+ public readonly NamedPipeServerStream Stream;
public Task Task;
public TaskStreamPair(NamedPipeServerStream stream, Task task)
@@ -321,8 +326,9 @@
// there must be an exact mapping between task index and stream index
Debug.Assert(_streams.Count == tasks.Count);
+ #pragma warning disable IDE0305 // see https://github.com/dotnet/roslyn/issues/70656 - yet unsolved
var index = Task.WaitAny(tasks.ToArray(), cancellationToken);
-
+ #pragma warning restore IDE0305
var trans = new ServerTransport(_streams[index].Stream, Configuration);
_streams.RemoveAt(index); // pass stream ownership to ServerTransport
diff --git a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs
index 31ecef3..43663c3 100644
--- a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs
@@ -22,6 +22,9 @@
using System.Threading.Tasks;
using Thrift.Transport.Client;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Transport.Server
{
diff --git a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
index 5366114..70857c5 100644
--- a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
@@ -18,6 +18,9 @@
using System.Threading;
using System.Threading.Tasks;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable IDE0290 // net8 - primary CTOR
+
namespace Thrift.Transport
{
// ReSharper disable once InconsistentNaming
@@ -40,14 +43,8 @@
public async ValueTask<TTransport> AcceptAsync(CancellationToken cancellationToken = default)
{
- var transport = await AcceptImplementationAsync(cancellationToken);
-
- if (transport == null)
- {
- throw new TTransportException($"{nameof(AcceptImplementationAsync)} should not return null");
- }
-
- return transport;
+ return await AcceptImplementationAsync(cancellationToken)
+ ?? throw new TTransportException($"{nameof(AcceptImplementationAsync)} should not return null");
}
}
}
diff --git a/lib/netstd/Thrift/Transport/TTransport.cs b/lib/netstd/Thrift/Transport/TTransport.cs
index 2f87ca0..4420224 100644
--- a/lib/netstd/Thrift/Transport/TTransport.cs
+++ b/lib/netstd/Thrift/Transport/TTransport.cs
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation(ASF) under one
+// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.The ASF licenses this file
@@ -21,6 +21,10 @@
using System.Threading;
using System.Threading.Tasks;
+#pragma warning disable IDE0079 // net20 - unneeded suppression
+#pragma warning disable CA1510 // net8 - use ThrowIfNull
+#pragma warning disable CA1513 // net8 - use ThrowIfNull
+
namespace Thrift.Transport
{
//TODO: think about client info
diff --git a/test/netstd/Client/Client.csproj b/test/netstd/Client/Client.csproj
index 1ae67fa..0e1eaa3 100644
--- a/test/netstd/Client/Client.csproj
+++ b/test/netstd/Client/Client.csproj
@@ -19,8 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
- <LangVersion>9.0</LangVersion>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<AssemblyName>Client</AssemblyName>
<PackageId>Client</PackageId>
<OutputType>Exe</OutputType>
@@ -49,8 +49,8 @@
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
</Exec>
- <Exec Condition="Exists('$(PathToThrift)')" Command=""$(PathToThrift)" -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
- <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
- <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('$(PathToThrift)')" Command=""$(PathToThrift)" -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
</Target>
</Project>
diff --git a/test/netstd/Client/Performance/PerformanceTests.cs b/test/netstd/Client/Performance/PerformanceTests.cs
index 6ac3aed..5262379 100644
--- a/test/netstd/Client/Performance/PerformanceTests.cs
+++ b/test/netstd/Client/Performance/PerformanceTests.cs
@@ -28,8 +28,6 @@
using System.Diagnostics;
using Thrift.Transport;
-#pragma warning disable CS1998 // no await in async method
-
namespace Client.Tests
{
public class PerformanceTests
@@ -44,7 +42,7 @@
internal static async Task<int> Execute()
{
var instance = new PerformanceTests();
- instance.ProtocolPeformanceTestAsync().Wait();
+ await instance.ProtocolPeformanceTestAsync();
// debug only
if (Debugger.IsAttached)
@@ -101,7 +99,7 @@
;
if (!Transport.IsOpen)
- Transport.OpenAsync().Wait();
+ await Transport.OpenAsync();
if (Activator.CreateInstance(typeof(T), Transport) is T instance)
return instance;
diff --git a/test/netstd/Client/TestClient.cs b/test/netstd/Client/TestClient.cs
index 3bf2daa..7486712 100644
--- a/test/netstd/Client/TestClient.cs
+++ b/test/netstd/Client/TestClient.cs
@@ -17,7 +17,6 @@
#pragma warning disable IDE0066 // switch expression
#pragma warning disable IDE0057 // substring
-#pragma warning disable CS1998 // no await in async method
using System;
using System.Collections.Generic;
@@ -93,19 +92,19 @@
}
else if (args[i].StartsWith("--pipe="))
{
- pipe = args[i].Substring(args[i].IndexOf("=") + 1);
+ pipe = args[i].Substring(args[i].IndexOf('=') + 1);
transport = TransportChoice.NamedPipe;
}
else if (args[i].StartsWith("--host="))
{
// check there for ipaddress
- host = args[i].Substring(args[i].IndexOf("=") + 1);
+ host = args[i].Substring(args[i].IndexOf('=') + 1);
if (transport != TransportChoice.TlsSocket)
transport = TransportChoice.Socket;
}
else if (args[i].StartsWith("--port="))
{
- port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
+ port = int.Parse(args[i].Substring(args[i].IndexOf('=') + 1));
if (transport != TransportChoice.TlsSocket)
transport = TransportChoice.Socket;
}
@@ -393,7 +392,7 @@
Console.WriteLine();
}
- public static async Task<int> Execute(List<string> args)
+ public static Task<int> Execute(List<string> args)
{
try
{
@@ -408,7 +407,7 @@
Console.WriteLine("*** FAILED ***");
Console.WriteLine("Error while parsing arguments");
Console.WriteLine("{0} {1}\nStack:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
- return ErrorUnknown;
+ return Task.FromResult(ErrorUnknown);
}
//issue tests on separate threads simultaneously
@@ -432,14 +431,14 @@
Task.WaitAll(tasks);
Console.WriteLine("Total time: " + (DateTime.Now - start));
Console.WriteLine();
- return retcode;
+ return Task.FromResult(retcode);
}
catch (Exception outerEx)
{
Console.WriteLine("*** FAILED ***");
Console.WriteLine("Unexpected error");
Console.WriteLine(outerEx.Message + "\n" + outerEx.StackTrace);
- return ErrorUnknown;
+ return Task.FromResult(ErrorUnknown);
}
}
@@ -646,8 +645,8 @@
var two = new CrazyNesting();
one.String_field = "crazy";
two.String_field = "crazy";
- one.Binary_field = new byte[] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
- two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
+ one.Binary_field = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF];
+ two.Binary_field = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF];
if (typeof(CrazyNesting).GetMethod("Equals")?.DeclaringType == typeof(CrazyNesting))
{
if (!one.Equals(two))
@@ -820,10 +819,7 @@
I32_thing = 8,
I64_thing = 8
};
- insane.Xtructs = new List<Xtruct>
- {
- truck
- };
+ insane.Xtructs = [ truck ];
Console.Write("testInsanity()");
var whoa = await client.testInsanity(insane, MakeTimeoutToken());
Console.Write(" = {");
diff --git a/test/netstd/Server/Server.csproj b/test/netstd/Server/Server.csproj
index 020b8d5..38a942a 100644
--- a/test/netstd/Server/Server.csproj
+++ b/test/netstd/Server/Server.csproj
@@ -19,8 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
- <LangVersion>9.0</LangVersion>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<AssemblyName>Server</AssemblyName>
<PackageId>Server</PackageId>
<OutputType>Exe</OutputType>
@@ -50,8 +50,8 @@
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
</Exec>
- <Exec Condition="Exists('$(PathToThrift)')" Command=""$(PathToThrift)" -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
- <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
- <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('$(PathToThrift)')" Command=""$(PathToThrift)" -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
+ <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../ThriftTest.thrift" />
</Target>
</Project>
diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs
index a540d19..2dea418 100644
--- a/test/netstd/Server/TestServer.cs
+++ b/test/netstd/Server/TestServer.cs
@@ -20,6 +20,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Reflection.Metadata.Ecma335;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
@@ -36,7 +37,6 @@
#pragma warning disable IDE0063 // using can be simplified, we don't
#pragma warning disable IDE0057 // substr can be simplified, we don't
-#pragma warning disable CS1998 // await missing
namespace ThriftTest
{
@@ -83,12 +83,12 @@
{
if (args[i].StartsWith("--pipe="))
{
- pipe = args[i].Substring(args[i].IndexOf("=") + 1);
+ pipe = args[i].Substring(args[i].IndexOf('=') + 1);
transport = TransportChoice.NamedPipe;
}
else if (args[i].StartsWith("--port="))
{
- port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
+ port = int.Parse(args[i].Substring(args[i].IndexOf('=') + 1));
if(transport != TransportChoice.TlsSocket)
transport = TransportChoice.Socket;
}
@@ -163,9 +163,8 @@
public class TestServer
{
- #pragma warning disable CA2211
- public static int _clientID = -1; // use with Interlocked only!
- #pragma warning restore CA2211
+ private static int _clientID = -1; // use with Interlocked only!
+ public static int ClientID => Interlocked.Add(ref _clientID, 0);
private static readonly TConfiguration Configuration = new();
@@ -181,10 +180,10 @@
return Task.CompletedTask;
}
- public async Task<object?> CreateContextAsync(TProtocol input, TProtocol output, CancellationToken cancellationToken)
+ public Task<object?> CreateContextAsync(TProtocol input, TProtocol output, CancellationToken cancellationToken)
{
callCount++;
- return null;
+ return Task.FromResult<object?>(null);
}
public Task DeleteContextAsync(object serverContext, TProtocol input, TProtocol output, CancellationToken cancellationToken)
@@ -268,7 +267,7 @@
public Task<byte[]> testBinary(byte[]? thing, CancellationToken cancellationToken)
{
logger.Invoke("testBinary({0} bytes)", thing?.Length ?? 0);
- return Task.FromResult(thing ?? Array.Empty<byte>());
+ return Task.FromResult(thing ?? []);
}
public Task<Guid> testUuid(Guid thing, CancellationToken cancellationToken)
@@ -318,7 +317,7 @@
}
sb.Append("}})");
logger.Invoke(sb.ToString());
- return Task.FromResult(thing ?? new Dictionary<int, int>()); // null returns are not allowed in Thrift
+ return Task.FromResult(thing ?? []); // null returns are not allowed in Thrift
}
public Task<Dictionary<string, string>> testStringMap(Dictionary<string, string>? thing, CancellationToken cancellationToken)
@@ -343,7 +342,7 @@
}
sb.Append("}})");
logger.Invoke(sb.ToString());
- return Task.FromResult(thing ?? new Dictionary<string, string>()); // null returns are not allowed in Thrift
+ return Task.FromResult(thing ?? []); // null returns are not allowed in Thrift
}
public Task<HashSet<int>> testSet(HashSet<int>? thing, CancellationToken cancellationToken)
@@ -368,7 +367,7 @@
}
sb.Append("}})");
logger.Invoke(sb.ToString());
- return Task.FromResult(thing ?? new HashSet<int>()); // null returns are not allowed in Thrift
+ return Task.FromResult(thing ?? []); // null returns are not allowed in Thrift
}
public Task<List<int>> testList(List<int>? thing, CancellationToken cancellationToken)
@@ -393,7 +392,7 @@
}
sb.Append("}})");
logger.Invoke(sb.ToString());
- return Task.FromResult(thing ?? new List<int>()); // null returns are not allowed in Thrift
+ return Task.FromResult(thing ?? []); // null returns are not allowed in Thrift
}
public Task<Numberz> testEnum(Numberz thing, CancellationToken cancellationToken)
diff --git a/tutorial/netstd/Client/Client.csproj b/tutorial/netstd/Client/Client.csproj
index ee0bc82..994d6be 100644
--- a/tutorial/netstd/Client/Client.csproj
+++ b/tutorial/netstd/Client/Client.csproj
@@ -19,8 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
- <LangVersion>9.0</LangVersion>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<AssemblyName>Client</AssemblyName>
<PackageId>Client</PackageId>
<OutputType>Exe</OutputType>
diff --git a/tutorial/netstd/Interfaces/Interfaces.csproj b/tutorial/netstd/Interfaces/Interfaces.csproj
index ff7891e..5ff8d9f 100644
--- a/tutorial/netstd/Interfaces/Interfaces.csproj
+++ b/tutorial/netstd/Interfaces/Interfaces.csproj
@@ -19,7 +19,7 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net6.0</TargetFramework>
<AssemblyName>Interfaces</AssemblyName>
<PackageId>Interfaces</PackageId>
<Version>0.20.0.0</Version>
diff --git a/tutorial/netstd/Server/Server.csproj b/tutorial/netstd/Server/Server.csproj
index 9aa3bc6..c72ec88 100644
--- a/tutorial/netstd/Server/Server.csproj
+++ b/tutorial/netstd/Server/Server.csproj
@@ -19,8 +19,8 @@
-->
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
- <LangVersion>9.0</LangVersion>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>latestMajor</LangVersion>
<AssemblyName>Server</AssemblyName>
<PackageId>Server</PackageId>
<OutputType>Exe</OutputType>