You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using Microsoft TypeSpec to auto-generate c# classes. However, there is a problem with the auto-generated .Equals method. In the default .mustache file of the openapi generator, there's a check for #isContainer which determins, if a regular comparison or .SequenceEqual should be used:
/// <summary>
/// Returns true if {{classname}} instances are equal
/// </summary>
/// <paramname="other">Instance of {{classname}} to be compared</param>
/// <returns>Boolean</returns>
public bool Equals({{classname}}? other)
{if (other is null) return false;if (ReferenceEquals(this, other)) return true; return {{#vars}}{{^isContainer}}
(
{{name}} == other.{{name}} ||
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&{{/vendorExtensions.x-is-value-type}}
{{name}}.Equals(other.{{name}})
){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
(
{{name}} == other.{{name}} ||
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&
other.{{name}} != null &&
{{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(other.{{name}})
){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
}
However, contrary to my expectation for the TypeSpec bytes data type (defined as an array of bytes), it doesn't use the SequenceEqual comparison, but the regular == one, which doesn't work for byte arrays in c#. Why is that?
bytes gets converted into a type: string, format: byte data type, which seems odd to me. Is that right?
Right now, it correctly generates a property of type byte[] in c#, but the equals method doesn't work, as it uses .Equals instead of the correct SequenceEqual.
We're using Microsoft TypeSpec to auto-generate c# classes. However, there is a problem with the auto-generated
.Equals
method. In the default .mustache file of the openapi generator, there's a check for#isContainer
which determins, if a regular comparison or.SequenceEqual
should be used:However, contrary to my expectation for the TypeSpec
bytes
data type (defined as an array of bytes), it doesn't use theSequenceEqual
comparison, but the regular==
one, which doesn't work for byte arrays in c#. Why is that?bytes
gets converted into atype: string, format: byte
data type, which seems odd to me. Is that right?Right now, it correctly generates a property of type
byte[]
in c#, but the equals method doesn't work, as it uses.Equals
instead of the correctSequenceEqual
.Reproduction
The text was updated successfully, but these errors were encountered: