Skip to content

Commit

Permalink
fix csharp formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed May 30, 2024
1 parent a90de9b commit ca74038
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr
| <${type.DeserializationAttributes()}>
| public partial interface I${vrapType.simpleClassName} ${if (extends.isNotEmpty()) { ": ${extends.joinToString(separator = ", ")}" } else ""}
| {
| <${type.toProperties()}>
| ${type.toProperties(" ")}
|
| <${type.subtypeFactories()}>
| }
Expand All @@ -65,10 +65,10 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr
)
}

private fun ObjectType.toProperties() : String = this.properties
private fun ObjectType.toProperties(indent: String = "") : String = this.properties
.filterNot { it.deprecated() }
.filterNot { property -> property.isPatternProperty() }
.map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n")
.map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n$indent")

private fun Property.toCsharpProperty(objectType: ObjectType): String {
val propName = this.name.firstUpperCase()
Expand All @@ -80,7 +80,7 @@ class CsharpModelInterfaceRenderer constructor(override val vrapTypeProvider: Vr
val deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n";

return """
|${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set;}${if (this.type.toVrapType() is VrapArrayType) """
|${deprecationAttr}${newKeyword}${typeName}$nullableChar $propName { get; set; }${if (this.type.toVrapType() is VrapArrayType) """
|${deprecationAttr}${newKeyword}IEnumerable\<${(this.type.toVrapType() as VrapArrayType).itemType.simpleName()}\>$nullableChar ${propName}Enumerable { set =\> $propName = value$nullableChar.ToList(); }
|""" else ""}
""".trimMargin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy
| ${if (type.markDeprecated()) "[Obsolete(\"usage of this endpoint has been deprecated.\", false)]" else ""}
| public partial class ${type.objectClassName()} : I${vrapType.simpleClassName}
| {
| <${if(type.isADictionaryType()) "" else type.toProperties()}>
| ${if(type.isADictionaryType()) "" else type.toProperties(" ")}
| <${type.renderConstructor(vrapType.simpleClassName)}>
| }
|}
Expand Down Expand Up @@ -70,10 +70,10 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy
"""
}

private fun ObjectType.toProperties() : String = this.allProperties
private fun ObjectType.toProperties(indent: String = "") : String = this.allProperties
.filterNot { it.deprecated() }
.filterNot { property -> property.isPatternProperty() }
.map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n")
.map { it.toCsharpProperty(this) }.joinToString(separator = "\n\n$indent")

private fun Property.toCsharpProperty(objectType: ObjectType): String {
val propName = this.name.firstUpperCase()
Expand All @@ -83,7 +83,7 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy
val deprecationAttr = if(this.deprecationAnnotation() == "") "" else this.deprecationAnnotation()+"\n";

return """
|${deprecationAttr}public ${typeName}$nullableChar $propName { get; set;}${if (this.type.toVrapType() is VrapArrayType) """
|${deprecationAttr}public ${typeName}$nullableChar $propName { get; set; }${if (this.type.toVrapType() is VrapArrayType) """
|${deprecationAttr}public IEnumerable\<${(this.type.toVrapType() as VrapArrayType).itemType.simpleName()}\>$nullableChar ${propName}Enumerable { set =\> $propName = value$nullableChar.ToList(); }
|""" else ""}
""".trimMargin()
Expand All @@ -103,8 +103,8 @@ class CsharpObjectTypeRenderer constructor(override val vrapTypeProvider: VrapTy
val isEmptyConstructor = this.getConstructorContentForDiscriminator() == "";
return if(!isEmptyConstructor)
"""public ${className}()
|{
| ${this.getConstructorContentForDiscriminator()}
|{
| ${this.getConstructorContentForDiscriminator()}
|}"""
else
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy
| {
| return JsonName;
| }
|
|
| IEnumerator IEnumerable.GetEnumerator()
| {
| return GetEnumerator();
Expand All @@ -55,21 +55,21 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy
| [EnumInterfaceCreator(typeof(I${vrapType.simpleClassName}), "FindEnum")]
| public interface I${vrapType.simpleClassName} : IJsonName, IEnumerable\<char\>
| {
| <${type.enumStaticFields("${vrapType.simpleClassName}")}>
| <${type.enumStaticFields("${vrapType.simpleClassName}")}>
|
| ${vrapType.simpleClassName}? Value { get; }
|
| ${vrapType.simpleClassName}? Value { get; }
|
| static I${vrapType.simpleClassName}[] Values()
| {
| return new[]
| {
| static I${vrapType.simpleClassName}[] Values()
| {
| return new[]
| {
| <${type.enumFieldsAsNames()}>
| };
| }
| static I${vrapType.simpleClassName} FindEnum(string value)
| {
| return Values().FirstOrDefault(origin =\> origin.JsonName == value) ?? new ${vrapType.simpleClassName}Wrapper() {JsonName = value};
| }
| }
| static I${vrapType.simpleClassName} FindEnum(string value)
| {
| return Values().FirstOrDefault(origin =\> origin.JsonName == value) ?? new ${vrapType.simpleClassName}Wrapper() { JsonName = value };
| }
| }
|}
""".trimMargin().keepIndentation()
Expand All @@ -95,18 +95,18 @@ class CsharpStringTypeRenderer constructor(override val vrapTypeProvider: VrapTy
?.map {
"""
|public static I${enumName} ${it.value.enumValueName()} = new ${enumName}Wrapper
| {Value = ${enumName}.${it.value.enumValueName()}, JsonName = "${it.value}"};
|{ Value = ${enumName}.${it.value.enumValueName()}, JsonName = "${it.value}" };
""".trimMargin()
}
?.joinToString(separator = "\n\n", postfix = "")

fun StringType.enumFieldsAsNames() = enumValues()
?.map {
"""
|${it.value.enumValueName()}
|${it.value.enumValueName()}
""".trimMargin()
}
?.joinToString(separator = ",\n", postfix = "")
?.joinToString(separator = " ,\n", postfix = "")


fun StringType.enumValues() = enum?.filter { it is StringInstance }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CsharpQueryPredicateRenderer constructor(val basePackage: String, override
| }
|
| <${type.allProperties.filterNot { it.deprecated() }.filterNot { it.isPatternProperty() }.joinToString("\n") { it.toBuilderDsl(type) }}>
|
|
| <${type.namedSubTypes().filterIsInstance<ObjectType>().joinToString("\n") { it.toBuilderDsl("As${it.subtypeName()}", vrapType) }}>
| }
|}
Expand Down

0 comments on commit ca74038

Please sign in to comment.