(&self, module: &ModuleDef, reducer: &spacetimedb_schema::def::ReducerDef)
| 751 | } |
| 752 | |
| 753 | fn generate_reducer_file(&self, module: &ModuleDef, reducer: &spacetimedb_schema::def::ReducerDef) -> OutputFile { |
| 754 | let mut output = CsharpAutogen::new( |
| 755 | self.namespace, |
| 756 | &[ |
| 757 | "SpacetimeDB.ClientApi", |
| 758 | "System.Collections.Generic", |
| 759 | "System.Runtime.Serialization", |
| 760 | ], |
| 761 | false, |
| 762 | ); |
| 763 | |
| 764 | writeln!(output, "public sealed partial class RemoteReducers : RemoteBase"); |
| 765 | indented_block(&mut output, |output| { |
| 766 | let func_name_pascal_case = reducer.accessor_name.deref().to_case(Case::Pascal); |
| 767 | let delegate_separator = if reducer.params_for_generate.elements.is_empty() { |
| 768 | "" |
| 769 | } else { |
| 770 | ", " |
| 771 | }; |
| 772 | |
| 773 | let (func_params, func_args) = |
| 774 | build_func_params_and_args(module, reducer.params_for_generate.into_iter(), self.namespace); |
| 775 | |
| 776 | writeln!( |
| 777 | output, |
| 778 | "public delegate void {func_name_pascal_case}Handler(ReducerEventContext ctx{delegate_separator}{func_params});" |
| 779 | ); |
| 780 | writeln!( |
| 781 | output, |
| 782 | "public event {func_name_pascal_case}Handler? On{func_name_pascal_case};" |
| 783 | ); |
| 784 | writeln!(output); |
| 785 | |
| 786 | if is_reducer_invokable(reducer) { |
| 787 | writeln!(output, "public void {func_name_pascal_case}({func_params})"); |
| 788 | indented_block(output, |output| { |
| 789 | writeln!( |
| 790 | output, |
| 791 | "conn.InternalCallReducer(new Reducer.{func_name_pascal_case}({func_args}));" |
| 792 | ); |
| 793 | }); |
| 794 | writeln!(output); |
| 795 | } |
| 796 | |
| 797 | writeln!( |
| 798 | output, |
| 799 | "public bool Invoke{func_name_pascal_case}(ReducerEventContext ctx, Reducer.{func_name_pascal_case} args)" |
| 800 | ); |
| 801 | indented_block(output, |output| { |
| 802 | writeln!(output, "if (On{func_name_pascal_case} == null)"); |
| 803 | indented_block(output, |output| { |
| 804 | writeln!(output, "if (InternalOnUnhandledReducerError != null)"); |
| 805 | indented_block(output, |output| { |
| 806 | writeln!(output, "switch(ctx.Event.Status)"); |
| 807 | indented_block(output, |output| { |
| 808 | writeln!(output, "case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;"); |
| 809 | writeln!(output, "case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception(\"out of energy\")); break;"); |
| 810 | }); |
nothing calls this directly
no test coverage detected