(
&self,
module: &ModuleDef,
procedure: &spacetimedb_schema::def::ProcedureDef,
)
| 855 | } |
| 856 | |
| 857 | fn generate_procedure_file( |
| 858 | &self, |
| 859 | module: &ModuleDef, |
| 860 | procedure: &spacetimedb_schema::def::ProcedureDef, |
| 861 | ) -> OutputFile { |
| 862 | let mut output = CsharpAutogen::new( |
| 863 | self.namespace, |
| 864 | &[ |
| 865 | "SpacetimeDB.ClientApi", |
| 866 | "System.Collections.Generic", |
| 867 | "System.Runtime.Serialization", |
| 868 | ], |
| 869 | false, |
| 870 | ); |
| 871 | |
| 872 | writeln!(output, "public sealed partial class RemoteProcedures : RemoteBase"); |
| 873 | indented_block(&mut output, |output| { |
| 874 | let func_name_pascal_case = procedure.accessor_name.deref().to_case(Case::Pascal); |
| 875 | let delegate_separator = if procedure.params_for_generate.elements.is_empty() { |
| 876 | "" |
| 877 | } else { |
| 878 | ", " |
| 879 | }; |
| 880 | |
| 881 | let (func_params, func_args) = |
| 882 | build_func_params_and_args(module, procedure.params_for_generate.into_iter(), self.namespace); |
| 883 | let return_type_str = ty_fmt_with_ns(module, &procedure.return_type_for_generate, self.namespace); |
| 884 | // Generate the clean public API that users call to allow us of BSATN.Decode<> then reflect to the proper return type |
| 885 | writeln!( |
| 886 | output, |
| 887 | "public void {func_name_pascal_case}({func_params}{delegate_separator}ProcedureCallback<{return_type_str}> callback)" |
| 888 | ); |
| 889 | indented_block(output, |output| { |
| 890 | writeln!(output, "// Convert the clean callback to the wrapper callback"); |
| 891 | writeln!( |
| 892 | output, |
| 893 | "Internal{func_name_pascal_case}({func_args}{delegate_separator}(ctx, result) => {{" |
| 894 | ); |
| 895 | |
| 896 | writeln!(output, "if (result.IsSuccess && result.Value != null)"); |
| 897 | indented_block(output, |output| { |
| 898 | writeln!( |
| 899 | output, |
| 900 | "callback(ctx, ProcedureCallbackResult<{return_type_str}>.Success(result.Value.Value));" |
| 901 | ); |
| 902 | }); |
| 903 | writeln!(output, "else"); |
| 904 | indented_block(output, |output| { |
| 905 | writeln!( |
| 906 | output, |
| 907 | "callback(ctx, ProcedureCallbackResult<{return_type_str}>.Failure(result.Error!));" |
| 908 | ); |
| 909 | }); |
| 910 | writeln!(output, "}});"); |
| 911 | }); |
| 912 | writeln!(output); |
| 913 | |
| 914 | // Generate the private wrapper method that handles BSATN |
nothing calls this directly
no test coverage detected