forked from loafle/openapi-generator-original
Merge pull request #1601 from wing328/csharp_obj_compare
[C#] Add Equal and GetHashCode to models
This commit is contained in:
commit
c6021da8a1
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -8,13 +9,15 @@ using Newtonsoft.Json;
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{packageName}}.Model {
|
||||
namespace {{packageName}}.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
|
||||
public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}}
|
||||
{
|
||||
{{#vars}}
|
||||
/// <summary>
|
||||
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
@ -26,28 +29,83 @@ namespace {{packageName}}.Model {
|
||||
{{/vars}}
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{#vars}}sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{/vars}}
|
||||
sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public {{#parent}} new {{/parent}}string ToJson() {
|
||||
public {{#parent}} new {{/parent}}string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as {{classname}});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if {{classname}} instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of {{classname}} to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals({{classname}} other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return {{#vars}}{{#isNotContainer}}
|
||||
(
|
||||
this.{{name}} == other.{{name}} ||
|
||||
this.{{name}} != null &&
|
||||
this.{{name}}.Equals(other.{{name}})
|
||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}}
|
||||
(
|
||||
this.{{name}} == other.{{name}} ||
|
||||
this.{{name}} != null &&
|
||||
this.{{name}}.SequenceEqual(other.{{name}})
|
||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
{{#vars}}
|
||||
if (this.{{name}} != null)
|
||||
hash = hash * 57 + this.{{name}}.GetHashCode();
|
||||
{{/vars}}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -6,13 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IO.Swagger.Model {
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class Category {
|
||||
public class Category : IEquatable<Category>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
@ -30,15 +33,14 @@ namespace IO.Swagger.Model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class Category {\n");
|
||||
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
|
||||
sb.Append(" Name: ").Append(Name).Append("\n");
|
||||
|
||||
sb.Append("}\n");
|
||||
@ -46,12 +48,70 @@ namespace IO.Swagger.Model {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as Category);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Category instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of Category to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Category other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == other.Id ||
|
||||
this.Id != null &&
|
||||
this.Id.Equals(other.Id)
|
||||
) &&
|
||||
(
|
||||
this.Name == other.Name ||
|
||||
this.Name != null &&
|
||||
this.Name.Equals(other.Name)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
|
||||
if (this.Id != null)
|
||||
hash = hash * 57 + this.Id.GetHashCode();
|
||||
|
||||
if (this.Name != null)
|
||||
hash = hash * 57 + this.Name.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -6,13 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IO.Swagger.Model {
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class Order {
|
||||
public class Order : IEquatable<Order>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
@ -59,23 +62,18 @@ namespace IO.Swagger.Model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class Order {\n");
|
||||
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
|
||||
sb.Append(" PetId: ").Append(PetId).Append("\n");
|
||||
|
||||
sb.Append(" Quantity: ").Append(Quantity).Append("\n");
|
||||
|
||||
sb.Append(" ShipDate: ").Append(ShipDate).Append("\n");
|
||||
|
||||
sb.Append(" Status: ").Append(Status).Append("\n");
|
||||
|
||||
sb.Append(" Complete: ").Append(Complete).Append("\n");
|
||||
|
||||
sb.Append("}\n");
|
||||
@ -83,12 +81,102 @@ namespace IO.Swagger.Model {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as Order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Order instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of Order to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Order other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == other.Id ||
|
||||
this.Id != null &&
|
||||
this.Id.Equals(other.Id)
|
||||
) &&
|
||||
(
|
||||
this.PetId == other.PetId ||
|
||||
this.PetId != null &&
|
||||
this.PetId.Equals(other.PetId)
|
||||
) &&
|
||||
(
|
||||
this.Quantity == other.Quantity ||
|
||||
this.Quantity != null &&
|
||||
this.Quantity.Equals(other.Quantity)
|
||||
) &&
|
||||
(
|
||||
this.ShipDate == other.ShipDate ||
|
||||
this.ShipDate != null &&
|
||||
this.ShipDate.Equals(other.ShipDate)
|
||||
) &&
|
||||
(
|
||||
this.Status == other.Status ||
|
||||
this.Status != null &&
|
||||
this.Status.Equals(other.Status)
|
||||
) &&
|
||||
(
|
||||
this.Complete == other.Complete ||
|
||||
this.Complete != null &&
|
||||
this.Complete.Equals(other.Complete)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
|
||||
if (this.Id != null)
|
||||
hash = hash * 57 + this.Id.GetHashCode();
|
||||
|
||||
if (this.PetId != null)
|
||||
hash = hash * 57 + this.PetId.GetHashCode();
|
||||
|
||||
if (this.Quantity != null)
|
||||
hash = hash * 57 + this.Quantity.GetHashCode();
|
||||
|
||||
if (this.ShipDate != null)
|
||||
hash = hash * 57 + this.ShipDate.GetHashCode();
|
||||
|
||||
if (this.Status != null)
|
||||
hash = hash * 57 + this.Status.GetHashCode();
|
||||
|
||||
if (this.Complete != null)
|
||||
hash = hash * 57 + this.Complete.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -6,13 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IO.Swagger.Model {
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class Pet {
|
||||
public class Pet : IEquatable<Pet>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
@ -59,23 +62,18 @@ namespace IO.Swagger.Model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class Pet {\n");
|
||||
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
|
||||
sb.Append(" Category: ").Append(Category).Append("\n");
|
||||
|
||||
sb.Append(" Name: ").Append(Name).Append("\n");
|
||||
|
||||
sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n");
|
||||
|
||||
sb.Append(" Tags: ").Append(Tags).Append("\n");
|
||||
|
||||
sb.Append(" Status: ").Append(Status).Append("\n");
|
||||
|
||||
sb.Append("}\n");
|
||||
@ -83,12 +81,102 @@ namespace IO.Swagger.Model {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as Pet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Pet instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of Pet to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Pet other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == other.Id ||
|
||||
this.Id != null &&
|
||||
this.Id.Equals(other.Id)
|
||||
) &&
|
||||
(
|
||||
this.Category == other.Category ||
|
||||
this.Category != null &&
|
||||
this.Category.Equals(other.Category)
|
||||
) &&
|
||||
(
|
||||
this.Name == other.Name ||
|
||||
this.Name != null &&
|
||||
this.Name.Equals(other.Name)
|
||||
) &&
|
||||
(
|
||||
this.PhotoUrls == other.PhotoUrls ||
|
||||
this.PhotoUrls != null &&
|
||||
this.PhotoUrls.SequenceEqual(other.PhotoUrls)
|
||||
) &&
|
||||
(
|
||||
this.Tags == other.Tags ||
|
||||
this.Tags != null &&
|
||||
this.Tags.SequenceEqual(other.Tags)
|
||||
) &&
|
||||
(
|
||||
this.Status == other.Status ||
|
||||
this.Status != null &&
|
||||
this.Status.Equals(other.Status)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
|
||||
if (this.Id != null)
|
||||
hash = hash * 57 + this.Id.GetHashCode();
|
||||
|
||||
if (this.Category != null)
|
||||
hash = hash * 57 + this.Category.GetHashCode();
|
||||
|
||||
if (this.Name != null)
|
||||
hash = hash * 57 + this.Name.GetHashCode();
|
||||
|
||||
if (this.PhotoUrls != null)
|
||||
hash = hash * 57 + this.PhotoUrls.GetHashCode();
|
||||
|
||||
if (this.Tags != null)
|
||||
hash = hash * 57 + this.Tags.GetHashCode();
|
||||
|
||||
if (this.Status != null)
|
||||
hash = hash * 57 + this.Status.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -6,13 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IO.Swagger.Model {
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class Tag {
|
||||
public class Tag : IEquatable<Tag>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
@ -30,15 +33,14 @@ namespace IO.Swagger.Model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class Tag {\n");
|
||||
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
|
||||
sb.Append(" Name: ").Append(Name).Append("\n");
|
||||
|
||||
sb.Append("}\n");
|
||||
@ -46,12 +48,70 @@ namespace IO.Swagger.Model {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as Tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Tag instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of Tag to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Tag other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == other.Id ||
|
||||
this.Id != null &&
|
||||
this.Id.Equals(other.Id)
|
||||
) &&
|
||||
(
|
||||
this.Name == other.Name ||
|
||||
this.Name != null &&
|
||||
this.Name.Equals(other.Name)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
|
||||
if (this.Id != null)
|
||||
hash = hash * 57 + this.Id.GetHashCode();
|
||||
|
||||
if (this.Name != null)
|
||||
hash = hash * 57 + this.Name.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
@ -6,13 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IO.Swagger.Model {
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class User {
|
||||
public class User : IEquatable<User>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
@ -73,27 +76,20 @@ namespace IO.Swagger.Model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class User {\n");
|
||||
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
|
||||
sb.Append(" Username: ").Append(Username).Append("\n");
|
||||
|
||||
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
|
||||
|
||||
sb.Append(" LastName: ").Append(LastName).Append("\n");
|
||||
|
||||
sb.Append(" Email: ").Append(Email).Append("\n");
|
||||
|
||||
sb.Append(" Password: ").Append(Password).Append("\n");
|
||||
|
||||
sb.Append(" Phone: ").Append(Phone).Append("\n");
|
||||
|
||||
sb.Append(" UserStatus: ").Append(UserStatus).Append("\n");
|
||||
|
||||
sb.Append("}\n");
|
||||
@ -101,12 +97,118 @@ namespace IO.Swagger.Model {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
return this.Equals(obj as User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if User instances are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Instance of User to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(User other)
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/10454552/677735
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == other.Id ||
|
||||
this.Id != null &&
|
||||
this.Id.Equals(other.Id)
|
||||
) &&
|
||||
(
|
||||
this.Username == other.Username ||
|
||||
this.Username != null &&
|
||||
this.Username.Equals(other.Username)
|
||||
) &&
|
||||
(
|
||||
this.FirstName == other.FirstName ||
|
||||
this.FirstName != null &&
|
||||
this.FirstName.Equals(other.FirstName)
|
||||
) &&
|
||||
(
|
||||
this.LastName == other.LastName ||
|
||||
this.LastName != null &&
|
||||
this.LastName.Equals(other.LastName)
|
||||
) &&
|
||||
(
|
||||
this.Email == other.Email ||
|
||||
this.Email != null &&
|
||||
this.Email.Equals(other.Email)
|
||||
) &&
|
||||
(
|
||||
this.Password == other.Password ||
|
||||
this.Password != null &&
|
||||
this.Password.Equals(other.Password)
|
||||
) &&
|
||||
(
|
||||
this.Phone == other.Phone ||
|
||||
this.Phone != null &&
|
||||
this.Phone.Equals(other.Phone)
|
||||
) &&
|
||||
(
|
||||
this.UserStatus == other.UserStatus ||
|
||||
this.UserStatus != null &&
|
||||
this.UserStatus.Equals(other.UserStatus)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// credit: http://stackoverflow.com/a/263416/677735
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hash = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
|
||||
if (this.Id != null)
|
||||
hash = hash * 57 + this.Id.GetHashCode();
|
||||
|
||||
if (this.Username != null)
|
||||
hash = hash * 57 + this.Username.GetHashCode();
|
||||
|
||||
if (this.FirstName != null)
|
||||
hash = hash * 57 + this.FirstName.GetHashCode();
|
||||
|
||||
if (this.LastName != null)
|
||||
hash = hash * 57 + this.LastName.GetHashCode();
|
||||
|
||||
if (this.Email != null)
|
||||
hash = hash * 57 + this.Email.GetHashCode();
|
||||
|
||||
if (this.Password != null)
|
||||
hash = hash * 57 + this.Password.GetHashCode();
|
||||
|
||||
if (this.Phone != null)
|
||||
hash = hash * 57 + this.Phone.GetHashCode();
|
||||
|
||||
if (this.UserStatus != null)
|
||||
hash = hash * 57 + this.UserStatus.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,25 @@
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="11" Column="2" />
|
||||
<File FileName="TestPet.cs" Line="8" Column="25" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="MonoDevelop.NUnit.TestPad">
|
||||
<State name="__root__">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClient" expanded="True">
|
||||
<Node name="TestPet" expanded="True">
|
||||
<Node name="TestPet" expanded="True">
|
||||
<Node name="TestEqual" selected="True" />
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</State>
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
|
@ -1,5 +1,6 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using IO.Swagger.Api;
|
||||
@ -144,6 +145,68 @@ namespace SwaggerClient.TestPet
|
||||
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestEqual()
|
||||
{
|
||||
// create pet
|
||||
Pet p1 = new Pet();
|
||||
p1.Id = petId;
|
||||
p1.Name = "Csharp test";
|
||||
p1.Status = "available";
|
||||
// create Category object
|
||||
Category category1 = new Category();
|
||||
category1.Id = 56;
|
||||
category1.Name = "sample category name2";
|
||||
List<String> photoUrls1 = new List<String>(new String[] {"sample photoUrls"});
|
||||
// create Tag object
|
||||
Tag tag1 = new Tag();
|
||||
tag1.Id = petId;
|
||||
tag1.Name = "sample tag name1";
|
||||
List<Tag> tags1 = new List<Tag>(new Tag[] {tag1});
|
||||
p1.Tags = tags1;
|
||||
p1.Category = category1;
|
||||
p1.PhotoUrls = photoUrls1;
|
||||
|
||||
// create pet 2
|
||||
Pet p2 = new Pet();
|
||||
p2.Id = petId;
|
||||
p2.Name = "Csharp test";
|
||||
p2.Status = "available";
|
||||
// create Category object
|
||||
Category category2 = new Category();
|
||||
category2.Id = 56;
|
||||
category2.Name = "sample category name2";
|
||||
List<String> photoUrls2 = new List<String>(new String[] {"sample photoUrls"});
|
||||
// create Tag object
|
||||
Tag tag2 = new Tag();
|
||||
tag2.Id = petId;
|
||||
tag2.Name = "sample tag name1";
|
||||
List<Tag> tags2 = new List<Tag>(new Tag[] {tag2});
|
||||
p2.Tags = tags2;
|
||||
p2.Category = category2;
|
||||
p2.PhotoUrls = photoUrls2;
|
||||
|
||||
// p1 and p2 should be equal (both object and attribute level)
|
||||
Assert.IsTrue (category1.Equals (category2));
|
||||
Assert.IsTrue (tags1.SequenceEqual (tags2));
|
||||
Assert.IsTrue (p1.PhotoUrls.SequenceEqual(p2.PhotoUrls));
|
||||
|
||||
Assert.IsTrue (p1.Equals (p2));
|
||||
|
||||
// update attribute to that p1 and p2 are not equal
|
||||
category2.Name = "new category name";
|
||||
Assert.IsFalse(category1.Equals (category2));
|
||||
|
||||
tags2 = new List<Tag> ();
|
||||
Assert.IsFalse (tags1.SequenceEqual (tags2));
|
||||
|
||||
// photoUrls has not changed so it should be equal
|
||||
Assert.IsTrue (p1.PhotoUrls.SequenceEqual(p2.PhotoUrls));
|
||||
|
||||
Assert.IsFalse (p1.Equals (p2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,8 +1,8 @@
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user