Repository: asyncapi/modelina (ts)

Issue:
[BUG] C# setter for property named `value` prevents assignment.
### Describe the bug.

A C# setter has a "magic" variable called `value` which contains the value being assigned.

If a model has a property called `Value`, then the generated setter is broken, as it will attempt to assign the magic variable, rather than the backing class field.

```c#
public partial class Duration
{
    private readonly decimal value;

    public decimal Value
    {
        get { return value; }
        // This setter is broken - it is assigning the setter-level value, not the class-level value.
        set { value = value; }
    }
}

### Expected behavior

The setter could be generated as `this.value = value`;

```c#
public decimal Value
{
    get { return value; }
    set { this.value = value; }
}
```


### Screenshots

N/A

### How to Reproduce

1. I opened the [online playground](https://modelina.org/playground?language=csharp).
2. I changed one of the field names to `value`.
3. I noted the C# setter was generated incorrectly, as described above.


### 🥦 Browser

Google Chrome

### 👀 Have you checked for similar open issues?

- [X] I checked and didn't find similar issue

### 🏢 Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)

### Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Pull request description:
fix: use this. for property setter in c# class renderer
## Description
The setter for c# class properties should use this.{propertyName} to assign values to avoid an edge case where there is a property named 'value'

## Related Issue
Fixes #1862 

## Checklist
- [x] The code follows the project's coding standards and is properly linted (`npm run lint`).
- [x] Tests have been added or updated to cover the changes.
- [ ] Documentation has been updated to reflect the changes.
- [x] All tests pass successfully locally.(`npm run test`).

## Additional Notes
<!-- Add any additional information or context that might be relevant to reviewers. -->


Patch:
diff --git a/examples/csharp-change-collection-type/__snapshots__/index.spec.ts.snap b/examples/csharp-change-collection-type/__snapshots__/index.spec.ts.snap
index e5a5a729..522e6e0a 100644
--- a/examples/csharp-change-collection-type/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-change-collection-type/__snapshots__/index.spec.ts.snap
@@ -9,7 +9,7 @@ Array [
   public IEnumerable<string>? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 }",
 ]
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 b051f6d9..9b6ffa3d 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
@@ -9,7 +9,7 @@ Array [
   public string? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 
   public override bool Equals(object obj)
diff --git a/examples/csharp-generate-json-serializer/__snapshots__/index.spec.ts.snap b/examples/csharp-generate-json-serializer/__snapshots__/index.spec.ts.snap
index d7829f96..6c6e5716 100644
--- a/examples/csharp-generate-json-serializer/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-generate-json-serializer/__snapshots__/index.spec.ts.snap
@@ -10,7 +10,7 @@ public partial class Root
   public string? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 }
 
diff --git a/examples/csharp-generate-newtonsoft-serializer/__snapshots__/index.spec.ts.snap b/examples/csharp-generate-newtonsoft-serializer/__snapshots__/index.spec.ts.snap
index a8b6fe0c..e13aa694 100644
--- a/examples/csharp-generate-newtonsoft-serializer/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-generate-newtonsoft-serializer/__snapshots__/index.spec.ts.snap
@@ -10,7 +10,7 @@ public partial class Root
   public string? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 }
 
diff --git a/examples/csharp-generate-required-properties/__snapshots__/index.spec.ts.snap b/examples/csharp-generate-required-properties/__snapshots__/index.spec.ts.snap
index 6ea50e9a..ac3d6230 100644
--- a/examples/csharp-generate-required-properties/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-generate-required-properties/__snapshots__/index.spec.ts.snap
@@ -12,25 +12,25 @@ Array [
   public bool RequiredBoolean 
   {
     get { return requiredBoolean; }
-    set { requiredBoolean = value; }
+    set { this.requiredBoolean = value; }
   }
 
   public bool? NotRequiredBoolean 
   {
     get { return notRequiredBoolean; }
-    set { notRequiredBoolean = value; }
+    set { this.notRequiredBoolean = value; }
   }
 
   public string RequiredString 
   {
     get { return requiredString; }
-    set { requiredString = value; }
+    set { this.requiredString = value; }
   }
 
   public string? NotRequiredString 
   {
     get { return notRequiredString; }
-    set { notRequiredString = value; }
+    set { this.notRequiredString = value; }
   }
 }",
 ]
diff --git a/examples/csharp-use-inheritance/__snapshots__/index.spec.ts.snap b/examples/csharp-use-inheritance/__snapshots__/index.spec.ts.snap
index 8e329c6b..7176a2d5 100644
--- a/examples/csharp-use-inheritance/__snapshots__/index.spec.ts.snap
+++ b/examples/csharp-use-inheritance/__snapshots__/index.spec.ts.snap
@@ -9,7 +9,7 @@ Array [
   public string[]? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 }",
 ]
diff --git a/examples/generate-csharp-models/__snapshots__/index.spec.ts.snap b/examples/generate-csharp-models/__snapshots__/index.spec.ts.snap
index a653e906..902c74d4 100644
--- a/examples/generate-csharp-models/__snapshots__/index.spec.ts.snap
+++ b/examples/generate-csharp-models/__snapshots__/index.spec.ts.snap
@@ -12,25 +12,25 @@ Array [
   public string? Email 
   {
     get { return email; }
-    set { email = value; }
+    set { this.email = value; }
   }
 
   public System.DateTime? Today 
   {
     get { return today; }
-    set { today = value; }
+    set { this.today = value; }
   }
 
   public System.TimeSpan? Duration 
   {
     get { return duration; }
-    set { duration = value; }
+    set { this.duration = value; }
   }
 
   public System.Guid? UserId 
   {
     get { return userId; }
-    set { userId = value; }
+    set { this.userId = value; }
   }
 }",
 ]
diff --git a/src/generators/csharp/renderers/ClassRenderer.ts b/src/generators/csharp/renderers/ClassRenderer.ts
index f0dc96e8..4d39151e 100644
--- a/src/generators/csharp/renderers/ClassRenderer.ts
+++ b/src/generators/csharp/renderers/ClassRenderer.ts
@@ -144,6 +144,6 @@ export const CSHARP_DEFAULT_CLASS_PRESET: CsharpClassPreset<CSharpOptions> = {
     if (options?.autoImplementedProperties) {
       return 'set;';
     }
-    return `set { ${property.propertyName} = value; }`;
+    return `set { this.${property.propertyName} = value; }`;
   }
 };


Test patch:
diff --git a/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap b/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap
index 995ae5e0..bcdfa542 100644
--- a/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap
+++ b/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap
@@ -21,13 +21,13 @@ exports[`CSharpGenerator class renderer should be able to overwrite property pre
   public string? Property 
   {
     get { return property; }
-    set { property = value; }
+    set { this.property = value; }
   }
 
   public Dictionary<string, string>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }"
 `;
@@ -48,55 +48,55 @@ exports[`CSharpGenerator should render \`class\` type 1`] = `
   public string StreetName 
   {
     get { return streetName; }
-    set { streetName = value; }
+    set { this.streetName = value; }
   }
 
   public string City 
   {
     get { return city; }
-    set { city = value; }
+    set { this.city = value; }
   }
 
   public string State 
   {
     get { return state; }
-    set { state = value; }
+    set { this.state = value; }
   }
 
   public double HouseNumber 
   {
     get { return houseNumber; }
-    set { houseNumber = value; }
+    set { this.houseNumber = value; }
   }
 
   public bool? Marriage 
   {
     get { return marriage; }
-    set { marriage = value; }
+    set { this.marriage = value; }
   }
 
   public dynamic? Members 
   {
     get { return members; }
-    set { members = value; }
+    set { this.members = value; }
   }
 
   public dynamic[]? TupleType 
   {
     get { return tupleType; }
-    set { tupleType = value; }
+    set { this.tupleType = value; }
   }
 
   public string[] ArrayType 
   {
     get { return arrayType; }
-    set { arrayType = value; }
+    set { this.arrayType = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }"
 `;
@@ -218,55 +218,55 @@ exports[`CSharpGenerator should render models and their dependencies 1`] = `
     public string StreetName 
     {
       get { return streetName; }
-      set { streetName = value; }
+      set { this.streetName = value; }
     }
 
     public string City 
     {
       get { return city; }
-      set { city = value; }
+      set { this.city = value; }
     }
 
     public string State 
     {
       get { return state; }
-      set { state = value; }
+      set { this.state = value; }
     }
 
     public double HouseNumber 
     {
       get { return houseNumber; }
-      set { houseNumber = value; }
+      set { this.houseNumber = value; }
     }
 
     public bool? Marriage 
     {
       get { return marriage; }
-      set { marriage = value; }
+      set { this.marriage = value; }
     }
 
     public dynamic? Members 
     {
       get { return members; }
-      set { members = value; }
+      set { this.members = value; }
     }
 
     public dynamic[] ArrayType 
     {
       get { return arrayType; }
-      set { arrayType = value; }
+      set { this.arrayType = value; }
     }
 
     public OtherModel? OtherModel 
     {
       get { return otherModel; }
-      set { otherModel = value; }
+      set { this.otherModel = value; }
     }
 
     public Dictionary<string, dynamic>? AdditionalProperties 
     {
       get { return additionalProperties; }
-      set { additionalProperties = value; }
+      set { this.additionalProperties = value; }
     }
   }
 }"
@@ -285,13 +285,13 @@ exports[`CSharpGenerator should render models and their dependencies 2`] = `
     public string? StreetName 
     {
       get { return streetName; }
-      set { streetName = value; }
+      set { this.streetName = value; }
     }
 
     public Dictionary<string, dynamic>? AdditionalProperties 
     {
       get { return additionalProperties; }
-      set { additionalProperties = value; }
+      set { this.additionalProperties = value; }
     }
   }
 }"
@@ -315,67 +315,67 @@ exports[`CSharpGenerator should render null-forgiving operator if handleNullable
   public string StreetName 
   {
     get { return streetName; }
-    set { streetName = value; }
+    set { this.streetName = value; }
   }
 
   public string City 
   {
     get { return city; }
-    set { city = value; }
+    set { this.city = value; }
   }
 
   public string State 
   {
     get { return state; }
-    set { state = value; }
+    set { this.state = value; }
   }
 
   public double HouseNumber 
   {
     get { return houseNumber; }
-    set { houseNumber = value; }
+    set { this.houseNumber = value; }
   }
 
   public bool? Marriage 
   {
     get { return marriage; }
-    set { marriage = value; }
+    set { this.marriage = value; }
   }
 
   public HouseType HouseType 
   {
     get { return houseType; }
-    set { houseType = value; }
+    set { this.houseType = value; }
   }
 
   public TerraceType? TerraceType 
   {
     get { return terraceType; }
-    set { terraceType = value; }
+    set { this.terraceType = value; }
   }
 
   public dynamic? Members 
   {
     get { return members; }
-    set { members = value; }
+    set { this.members = value; }
   }
 
   public dynamic[]? TupleType 
   {
     get { return tupleType; }
-    set { tupleType = value; }
+    set { this.tupleType = value; }
   }
 
   public string[] ArrayType 
   {
     get { return arrayType; }
-    set { arrayType = value; }
+    set { this.arrayType = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }"
 `;
diff --git a/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap b/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
index f62f475f..f0a235e2 100644
--- a/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
+++ b/test/generators/csharp/presets/__snapshots__/CommonPreset.spec.ts.snap
@@ -11,25 +11,25 @@ exports[`CSHARP_COMMON_PRESET should render Equals support function 1`] = `
   public string StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public double? NumberProp 
   {
     get { return numberProp; }
-    set { numberProp = value; }
+    set { this.numberProp = value; }
   }
 
   public NestedTest? ObjectProp 
   {
     get { return objectProp; }
-    set { objectProp = value; }
+    set { this.objectProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 
   public override bool Equals(object obj)
@@ -67,13 +67,13 @@ exports[`CSHARP_COMMON_PRESET should render Equals support function 2`] = `
   public string? StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 
   public override bool Equals(object obj)
@@ -109,25 +109,25 @@ exports[`CSHARP_COMMON_PRESET should render GetHashCode support function 1`] = `
   public string StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public double? NumberProp 
   {
     get { return numberProp; }
-    set { numberProp = value; }
+    set { this.numberProp = value; }
   }
 
   public NestedTest? ObjectProp 
   {
     get { return objectProp; }
-    set { objectProp = value; }
+    set { this.objectProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 
   public override int GetHashCode()
@@ -151,13 +151,13 @@ exports[`CSHARP_COMMON_PRESET should render GetHashCode support function 2`] = `
   public string? StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 
   public override int GetHashCode()
diff --git a/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap b/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap
index 21ac5765..cc662ff6 100644
--- a/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap
+++ b/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap
@@ -13,31 +13,31 @@ public partial class Test
   public string StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public double? NumberProp 
   {
     get { return numberProp; }
-    set { numberProp = value; }
+    set { this.numberProp = value; }
   }
 
   public EnumTest? EnumProp 
   {
     get { return enumProp; }
-    set { enumProp = value; }
+    set { this.enumProp = value; }
   }
 
   public NestedTest? ObjectProp 
   {
     get { return objectProp; }
-    set { objectProp = value; }
+    set { this.objectProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }
 
@@ -204,13 +204,13 @@ public partial class NestedTest
   public string? StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }
 
diff --git a/test/generators/csharp/presets/__snapshots__/NewtonsoftSerializerPreset.spec.ts.snap b/test/generators/csharp/presets/__snapshots__/NewtonsoftSerializerPreset.spec.ts.snap
index 3f7da982..c6b1af16 100644
--- a/test/generators/csharp/presets/__snapshots__/NewtonsoftSerializerPreset.spec.ts.snap
+++ b/test/generators/csharp/presets/__snapshots__/NewtonsoftSerializerPreset.spec.ts.snap
@@ -13,31 +13,31 @@ public partial class Test
   public string StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public double? NumberProp 
   {
     get { return numberProp; }
-    set { numberProp = value; }
+    set { this.numberProp = value; }
   }
 
   public EnumTest? EnumProp 
   {
     get { return enumProp; }
-    set { enumProp = value; }
+    set { this.enumProp = value; }
   }
 
   public NestedTest? ObjectProp 
   {
     get { return objectProp; }
-    set { objectProp = value; }
+    set { this.objectProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }
 
@@ -160,13 +160,13 @@ public partial class NestedTest
   public string? StringProp 
   {
     get { return stringProp; }
-    set { stringProp = value; }
+    set { this.stringProp = value; }
   }
 
   public Dictionary<string, dynamic>? AdditionalProperties 
   {
     get { return additionalProperties; }
-    set { additionalProperties = value; }
+    set { this.additionalProperties = value; }
   }
 }