Skip to content

Commit

Permalink
chore: merge branch master into next
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Mar 10, 2024
2 parents 505f373 + 0f37a3a commit 9869a67
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,30 @@
"doc",
"test"
]
},
{
"login": "Souvikns",
"name": "souvik",
"avatar_url": "https://avatars.githubusercontent.com/u/41781438?v=4",
"profile": "https://github.com/Souvikns",
"contributions": [
"code",
"test",
"example",
"doc"
]
},
{
"login": "Louis-PhilippeGentile",
"name": "Louis-PhilippeGentile",
"avatar_url": "https://avatars.githubusercontent.com/u/43426946?v=4",
"profile": "https://github.com/Louis-PhilippeGentile",
"contributions": [
"code",
"test",
"doc",
"bug"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
[![Playground](https://img.shields.io/website?label=playground&url=https%3A%2F%2Fwww.modelina.org%2Fplayground)](https://www.modelina.org/playground) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-81-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-83-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Your one-stop tool for generating accurate and well-tested models for representing the message payloads. Use it as a tool in your development workflow, or a library in a larger integrations, entirely in your control.
Expand Down Expand Up @@ -427,6 +427,8 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<td align="center" valign="top" width="14.28%"><a href="https://moritzkalwa.dev/"><img src="https://avatars.githubusercontent.com/u/62842654?v=4?s=100" width="100px;" alt="Moritz Kalwa"/><br /><sub><b>Moritz Kalwa</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3Amoritzkalwa" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/modelina/commits?author=moritzkalwa" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/akkshitgupta"><img src="https://avatars.githubusercontent.com/u/96991785?v=4?s=100" width="100px;" alt="Akshit Gupta"/><br /><sub><b>Akshit Gupta</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=akkshitgupta" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3Aakkshitgupta" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Athul0491"><img src="https://avatars.githubusercontent.com/u/65664185?v=4?s=100" width="100px;" alt="Athul Tulasidasan"/><br /><sub><b>Athul Tulasidasan</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Code">💻</a> <a href="#example-Athul0491" title="Examples">💡</a> <a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Documentation">📖</a> <a href="https://github.com/asyncapi/modelina/commits?author=Athul0491" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Souvikns"><img src="https://avatars.githubusercontent.com/u/41781438?v=4?s=100" width="100px;" alt="souvik"/><br /><sub><b>souvik</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Souvikns" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=Souvikns" title="Tests">⚠️</a> <a href="#example-Souvikns" title="Examples">💡</a> <a href="https://github.com/asyncapi/modelina/commits?author=Souvikns" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Louis-PhilippeGentile"><img src="https://avatars.githubusercontent.com/u/43426946?v=4?s=100" width="100px;" alt="Louis-PhilippeGentile"/><br /><sub><b>Louis-PhilippeGentile</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Louis-PhilippeGentile" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=Louis-PhilippeGentile" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/modelina/commits?author=Louis-PhilippeGentile" title="Documentation">📖</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3ALouis-PhilippeGentile" title="Bug reports">🐛</a></td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 4 additions & 2 deletions docs/languages/Csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ Currently not supported, [let everyone know you need it](https://github.com/asyn

## Generate models with equals and GetHashCode methods

To overwrite the `Equal` and `GetHashCode` methods, use the preset `CSHARP_COMMON_PRESET` and provide the options `equal: true` and `hashCode: true`
To overwrite the `Equals` and `GetHashCode` methods, use the preset `CSHARP_COMMON_PRESET` and provide the options `equal: true` and `hashCode: true`

Check out this [example for a live demonstration](../../examples/csharp-generate-equals-and-hashcode).

Note that the `Equals` method uses `Object.Equals(objA, objB)`. This means that [reference types properties](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types) that do not override their default `Equals` method will perform a reference equality check to determine equality, returning `false` if they do not reference the same object.

## Generate models with auto-implemented properties

To generate auto-implemented properties (the ones with with `{ get; set; }` accessors), use the preset `CSHARP_COMMON_PRESET` and provide the option `autoImplementedProperties: true`
To generate auto-implemented properties (the ones with `{ get; set; }` accessors), use the preset `CSHARP_COMMON_PRESET` and provide the option `autoImplementedProperties: true`

Check out this [example for a live demonstration](../../examples/csharp-auto-implemented-properties).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Array [
if(obj is Root model)
{
if(ReferenceEquals(this, model)) { return true; }
return Email == model.Email;
return Object.Equals(Email, model.Email);
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/generators/csharp/presets/CommonPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function renderEqual({
let equalProperties = propertyKeys
.map((propertyName) => {
const accessorMethodProp = FormatHelpers.upperFirst(propertyName);
return `${accessorMethodProp} == model.${accessorMethodProp}`;
return `Object.Equals(${accessorMethodProp}, model.${accessorMethodProp})`;
})
.join(' && \n');
equalProperties = `return ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ exports[`CSHARP_COMMON_PRESET should render Equals support function 1`] = `
if(obj is Test model)
{
if(ReferenceEquals(this, model)) { return true; }
return StringProp == model.StringProp &&
NumberProp == model.NumberProp &&
ObjectProp == model.ObjectProp &&
AdditionalProperties == model.AdditionalProperties;
return Object.Equals(StringProp, model.StringProp) &&
Object.Equals(NumberProp, model.NumberProp) &&
Object.Equals(ObjectProp, model.ObjectProp) &&
Object.Equals(AdditionalProperties, model.AdditionalProperties);
}
return false;
Expand Down Expand Up @@ -81,8 +81,8 @@ exports[`CSHARP_COMMON_PRESET should render Equals support function 2`] = `
if(obj is NestedTest model)
{
if(ReferenceEquals(this, model)) { return true; }
return StringProp == model.StringProp &&
AdditionalProperties == model.AdditionalProperties;
return Object.Equals(StringProp, model.StringProp) &&
Object.Equals(AdditionalProperties, model.AdditionalProperties);
}
return false;
Expand Down

0 comments on commit 9869a67

Please sign in to comment.