Skip to content

Commit

Permalink
fix: presets options to generic in csharp (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samridhi-98 authored Apr 20, 2022
1 parent ec05afd commit 9e7ac02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/generators/csharp/CSharpPreset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
import { Preset, EnumPreset, ClassPreset, PresetArgs, PropertyArgs } from '../../models';
import { ClassRenderer, CSHARP_DEFAULT_CLASS_PRESET } from './renderers/ClassRenderer';
import { CSHARP_DEFAULT_ENUM_PRESET, EnumRenderer } from './renderers/EnumRenderer';
Expand All @@ -7,9 +8,9 @@ export interface CsharpClassPreset extends ClassPreset<ClassRenderer> {
accessor?: (args: PresetArgs<ClassRenderer, any> & PropertyArgs) => Promise<string> | string;
}

export type CSharpPreset = Preset<{
export type CSharpPreset<O extends object = any> = Preset<{
class: CsharpClassPreset;
enum: EnumPreset<EnumRenderer>
enum: EnumPreset<EnumRenderer, O>
}>;

export const CSHARP_DEFAULT_PRESET: CSharpPreset = {
Expand Down
10 changes: 5 additions & 5 deletions src/generators/csharp/presets/CommonPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ${renderer.indent(equalProperties, 4)};
}
return false;
}`;
}
}

/**
* Render `hashCode` function based on model's properties
Expand All @@ -66,20 +66,20 @@ ${renderer.indent(hashProperties, 2)}
return hash.ToHashCode();
}
`;
}
}

/**
* Preset which adds `Equals`, `GetHashCode` functions to class.
*
* @implements {CSharpPreset}
*/
export const CSHARP_COMMON_PRESET: CSharpPreset = {
export const CSHARP_COMMON_PRESET: CSharpPreset<CSharpCommonPresetOptions> = {
class: {
additionalContent({ renderer, model, content, options }) {
options = options || {};
const blocks: string[] = [];
if (options.equal === undefined || options.equal === true) {blocks.push(renderEqual({ renderer, model }));}

if (options.equal === undefined || options.equal === true) { blocks.push(renderEqual({ renderer, model })); }
if (options.hashCode === undefined || options.hashCode === true) {
renderer.addDependency('using System;');
blocks.push(renderHashCode({ renderer, model }));
Expand Down

0 comments on commit 9e7ac02

Please sign in to comment.