diff --git a/.all-contributorsrc b/.all-contributorsrc
index 010c895da5..a4d88bbc84 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -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,
diff --git a/README.md b/README.md
index 277ea28cb2..c24fe66d00 100644
--- a/README.md
+++ b/README.md
@@ -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](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-)
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.
@@ -427,6 +427,8 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
Moritz Kalwa 💻 ⚠️ 🐛 📖 |
Akshit Gupta 💻 🐛 |
Athul Tulasidasan 💻 💡 📖 ⚠️ |
+ souvik 💻 ⚠️ 💡 📖 |
+ Louis-PhilippeGentile 💻 ⚠️ 📖 🐛 |
diff --git a/docs/languages/Csharp.md b/docs/languages/Csharp.md
index 965735b8c1..bf48c37e9d 100644
--- a/docs/languages/Csharp.md
+++ b/docs/languages/Csharp.md
@@ -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).
diff --git a/examples/csharp-generate-equals-and-hashcode/__snapshots__/index.spec.ts.snap b/examples/csharp-generate-equals-and-hashcode/__snapshots__/index.spec.ts.snap
index ba1e2ddf0b..b051f6d96b 100644
--- a/examples/csharp-generate-equals-and-hashcode/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-generate-equals-and-hashcode/__snapshots__/index.spec.ts.snap
@@ -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;
diff --git a/src/generators/csharp/presets/CommonPreset.ts b/src/generators/csharp/presets/CommonPreset.ts
index c1002306d2..2c23eb22d1 100644
--- a/src/generators/csharp/presets/CommonPreset.ts
+++ b/src/generators/csharp/presets/CommonPreset.ts
@@ -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 ${
diff --git a/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap b/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
index 633fa9fe7c..f62f475f4a 100644
--- a/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
+++ b/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
@@ -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;
@@ -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;