Skip to content

Commit

Permalink
add functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jul 28, 2024
1 parent 9f9fc78 commit 506afdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/generators/csharp/CSharpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ export class CSharpGenerator extends AbstractGenerator<
? ''
: `${outputModel.dependencies.join('\n')}\n\n`;

const outputContent = `namespace ${completeModelOptionsToUse.namespace}
const outputContent = `${outputDependencies}
namespace ${completeModelOptionsToUse.namespace}
{
${FormatHelpers.indent(
outputDependencies + outputModel.result,
outputModel.result,
optionsToUse.indentation?.size,
optionsToUse.indentation?.type
)}
Expand Down
11 changes: 11 additions & 0 deletions src/generators/csharp/presets/NewtonsoftSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ function renderDeserialize({
export const CSHARP_NEWTONSOFT_SERIALIZER_PRESET: CSharpPreset<CSharpOptions> =
{
class: {
additionalContent: ({content, model, renderer}) => {
return renderer.indent(`${content}
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
public static ${model.name} Deserialize(string json)
{
return JsonConvert.DeserializeObject<${model.name}>(json);
}`);
},
self: ({ renderer, content, model }) => {
renderer.dependencyManager.addDependency('using Newtonsoft.Json;');
renderer.dependencyManager.addDependency('using Newtonsoft.Json.Linq;');
Expand Down

0 comments on commit 506afdd

Please sign in to comment.