diff --git a/docs/migrations/version-2-to-3.md b/docs/migrations/version-2-to-3.md index 68186b8c1c..e32f012407 100644 --- a/docs/migrations/version-2-to-3.md +++ b/docs/migrations/version-2-to-3.md @@ -12,7 +12,68 @@ Is not affected by this change. ### C# -Is not affected by this change. +#### System.TimeSpan is used when format is time + +This example used to generate a `string`, but is now instead using `System.TimeSpan`. + +```yaml +type: object +properties: + duration: + type: string + format: time +``` + +will generate + +```csharp +public class TestClass { + private System.TimeSpan duration; + ... +} +``` + +#### System.DateTime is used when format is date-time + +This example used to generate a `string`, but is now instead using `System.DateTime`. + +```yaml +type: object +properties: + dob: + type: string + format: date-time +``` + +will generate + +```csharp +public class TestClass { + private System.DateTime dob; + ... +} +``` + +#### System.Guid is used when format is uuid + +This example used to generate a `string`, but is now instead using `System.Guid`. + +```yaml +type: object +properties: + uniqueId: + type: string + format: uuid +``` + +will generate + +```csharp +public class TestClass { + private System.Guid uniqueId; + ... +} +``` ### Java diff --git a/examples/generate-csharp-models/package-lock.json b/examples/generate-csharp-models/package-lock.json index 56ab4e873b..c6c4ae4e1d 100644 --- a/examples/generate-csharp-models/package-lock.json +++ b/examples/generate-csharp-models/package-lock.json @@ -1,5 +1,5 @@ { - "name": "typescript-interface", + "name": "generate-csharp-models", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/test/generators/csharp/CSharpConstrainer.spec.ts b/test/generators/csharp/CSharpConstrainer.spec.ts index da9b035e3f..26fbb989d9 100644 --- a/test/generators/csharp/CSharpConstrainer.spec.ts +++ b/test/generators/csharp/CSharpConstrainer.spec.ts @@ -94,7 +94,12 @@ describe('CSharpConstrainer', () => { expect(type).toEqual('string'); }); test('should render System.DateTime', () => { - const model = new ConstrainedStringModel('test', undefined, { format: 'date-time' }, ''); + const model = new ConstrainedStringModel( + 'test', + undefined, + { format: 'date-time' }, + '' + ); const type = CSharpDefaultTypeMapping.String({ constrainedModel: model, ...defaultOptions @@ -102,7 +107,12 @@ describe('CSharpConstrainer', () => { expect(type).toEqual('System.DateTime'); }); test('should render TimeSpan', () => { - const model = new ConstrainedStringModel('test', undefined, { format: 'time' }, ''); + const model = new ConstrainedStringModel( + 'test', + undefined, + { format: 'time' }, + '' + ); const type = CSharpDefaultTypeMapping.String({ constrainedModel: model, ...defaultOptions @@ -110,7 +120,12 @@ describe('CSharpConstrainer', () => { expect(type).toEqual('System.TimeSpan'); }); test('should render Guid', () => { - const model = new ConstrainedStringModel('test', undefined, { format: 'uuid' }, ''); + const model = new ConstrainedStringModel( + 'test', + undefined, + { format: 'uuid' }, + '' + ); const type = CSharpDefaultTypeMapping.String({ constrainedModel: model, ...defaultOptions