diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 4bc76d2f8..33fcea410 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -145,6 +145,15 @@ public function getIdentifierOverrides(): array ]; } + public function getPropertyOverrides(): array + { + return [ + 'provider' => [ + 'Provider' => 'MessagingProvider', + ], + ]; + } + /** * @param array $parameter * @return string @@ -428,6 +437,12 @@ public function getFilters(): array new TwigFilter('caseEnumKey', function (string $value) { return $this->toPascalCase($value); }), + new TwigFilter('overrideProperty', function (string $property, string $class) { + if (isset($this->getPropertyOverrides()[$class][$property])) { + return $this->getPropertyOverrides()[$class][$property]; + } + return $property; + }), ]; } } diff --git a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig index 8c6a46714..af68ab567 100644 --- a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig +++ b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig @@ -6,12 +6,12 @@ namespace {{ spec.title | caseUcfirst }}.Converters { public class ValueClassConverter : JsonConverter { - public override bool CanConvert(Type objectType) + public override bool CanConvert(System.Type objectType) { return typeof(IEnum).IsAssignableFrom(objectType); } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer) { var value = (string)reader.Value; var constructor = objectType.GetConstructor(new[] { typeof(string) }); diff --git a/templates/dotnet/src/Appwrite/Models/Model.cs.twig b/templates/dotnet/src/Appwrite/Models/Model.cs.twig index 6e83a251a..43e871312 100644 --- a/templates/dotnet/src/Appwrite/Models/Model.cs.twig +++ b/templates/dotnet/src/Appwrite/Models/Model.cs.twig @@ -1,5 +1,5 @@ {% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>{% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}{% endif %}{% else %}{{property | typeName}}{% endif %}{% if not property.required %}?{% endif %}{% endmacro %} -{% macro property_name(definition, property) %}{{ property.name | caseUcfirst | removeDollarSign | escapeKeyword}}{% endmacro %} +{% macro property_name(definition, property) %}{{ property.name | caseUcfirst | removeDollarSign | escapeKeyword }}{% endmacro %} using System; using System.Linq; @@ -14,7 +14,7 @@ namespace {{ spec.title | caseUcfirst }}.Models { {%~ for property in definition.properties %} [JsonProperty("{{ property.name }}")] - public {{ _self.sub_schema(property) }} {{ _self.property_name(definition, property) }} { get; private set; } + public {{ _self.sub_schema(property) }} {{ _self.property_name(definition, property) | overrideProperty(definition.name) }} { get; private set; } {%~ endfor %} {%~ if definition.additionalProperties %} @@ -31,7 +31,7 @@ namespace {{ spec.title | caseUcfirst }}.Models {%~ endif %} ) { {%~ for property in definition.properties %} - {{ _self.property_name(definition, property) }} = {{ property.name | caseCamel | escapeKeyword }}; + {{ _self.property_name(definition, property) | overrideProperty(definition.name) }} = {{ property.name | caseCamel | escapeKeyword }}; {%~ endfor %} {%~ if definition.additionalProperties %} Data = data; @@ -51,7 +51,7 @@ namespace {{ spec.title | caseUcfirst }}.Models public Dictionary ToMap() => new Dictionary() { {%~ for property in definition.properties %} - { "{{ property.name }}", {% if property.sub_schema %}{% if property.type == 'array' %}{{ _self.property_name(definition, property) }}.Select(it => it.ToMap()){% else %}{{ _self.property_name(definition, property) }}.ToMap(){% endif %}{% else %}{{ _self.property_name(definition, property) }}{% endif %}{{ ' }' }}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} + { "{{ property.name }}", {% if property.sub_schema %}{% if property.type == 'array' %}{{ _self.property_name(definition, property) | overrideProperty(definition.name) }}.Select(it => it.ToMap()){% else %}{{ _self.property_name(definition, property) | overrideProperty(definition.name) }}.ToMap(){% endif %}{% else %}{{ _self.property_name(definition, property) | overrideProperty(definition.name) }}{% endif %}{{ ' }' }}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} {%~ endfor %} {%~ if definition.additionalProperties %}