} //if you set to true (like for a game package), then if not set, then will raise exception. public static JsonSerializerOptions GetOptionsForAspnetCore() { var options = new JsonSerializerOptions(); options.AddDateTimeConvertersAndIndent(); ConvertersHelpers.PopulateConverters(options); return(options); }
//decided to make it public. this means if i am doing from client and want the proper options (including using custom source generators, can do). in this case, has to know the type to use. public static JsonSerializerOptions GetCustomJsonSerializerOptions <T>() { if (JsonOptionsHelpers <T> .Options is not null) { return(JsonOptionsHelpers <T> .Options); } var options = new JsonSerializerOptions(); options.AddDateTimeConvertersAndIndent(); ConvertersHelpers.PopulateConverters(options); Action <JsonSerializerOptions>?action = MultipleContextHelpers <T> .ContextAction; if (action is not null) { action.Invoke(options); } JsonOptionsHelpers <T> .Options = options; return(JsonOptionsHelpers <T> .Options); }