add equal and gethashcode to C# model

This commit is contained in:
wing328 2015-11-21 13:22:00 +08:00
parent c150247dca
commit 1ce3b67aa4
12 changed files with 883 additions and 392 deletions

View File

@ -8,46 +8,98 @@ using Newtonsoft.Json;
{{#models}} {{#models}}
{{#model}} {{#model}}
namespace {{packageName}}.Model { namespace {{packageName}}.Model
{
/// <summary>
/// {{description}}
/// </summary>
[DataContract]
public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
{{#vars}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
public {{{datatype}}} {{name}} { get; set; }
{{/vars}}
/// <summary> /// <summary>
/// Get the string presentation of the object /// {{description}}
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}}
var sb = new StringBuilder(); {
sb.Append("class {{classname}} {\n"); {{#vars}}
{{#vars}} /// <summary>
sb.Append(" {{name}}: ").Append({{name}}).Append("\n"); /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
{{/vars}} /// </summary>{{#description}}
sb.Append("}\n"); /// <value>{{{description}}}</value>{{/description}}
return sb.ToString(); [DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
} public {{{datatype}}} {{name}} { get; set; }
{{/vars}}
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class {{classname}} {\n");
{{#vars}}sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
{{/vars}}
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public {{#parent}} new {{/parent}}string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
/// <summary> /// <summary>
/// Get the JSON string presentation of the object /// Returns true if objects are equal
/// </summary> /// </summary>
/// <returns>JSON string presentation of the object</returns> /// <param name="obj">Object to be compared</param>
public {{#parent}} new {{/parent}}string ToJson() { /// <returns>Boolean</returns>
return JsonConvert.SerializeObject(this, Formatting.Indented); 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}}
(
this.{{name}} == other.{{name}} ||
this.{{name}} != null &&
this.{{name}}.Equals(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/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}} {{/model}}
{{/models}} {{/models}}
} }

View File

@ -6,52 +6,111 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model { namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Category {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary> /// <summary>
/// Get the string presentation of the object ///
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class Category : IEquatable<Category>
var sb = new StringBuilder(); {
sb.Append("class Category {\n");
/// <summary>
sb.Append(" Id: ").Append(Id).Append("\n"); /// Gets or Sets Id
/// </summary>
sb.Append(" Name: ").Append(Name).Append("\n"); [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
sb.Append("}\n");
return sb.ToString();
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
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");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
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;
}
}
} }
/// <summary>
/// Get the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
} }

View File

@ -6,89 +6,176 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model { namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Order {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
public long? PetId { get; set; }
/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
public int? Quantity { get; set; }
/// <summary>
/// Gets or Sets ShipDate
/// </summary>
[DataMember(Name="shipDate", EmitDefaultValue=false)]
public DateTime? ShipDate { get; set; }
/// <summary>
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
public bool? Complete { get; set; }
/// <summary> /// <summary>
/// Get the string presentation of the object ///
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class Order : IEquatable<Order>
var sb = new StringBuilder(); {
sb.Append("class Order {\n");
/// <summary>
sb.Append(" Id: ").Append(Id).Append("\n"); /// Gets or Sets Id
/// </summary>
sb.Append(" PetId: ").Append(PetId).Append("\n"); [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
sb.Append(" Quantity: ").Append(Quantity).Append("\n");
sb.Append(" ShipDate: ").Append(ShipDate).Append("\n"); /// <summary>
/// Gets or Sets PetId
sb.Append(" Status: ").Append(Status).Append("\n"); /// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
sb.Append(" Complete: ").Append(Complete).Append("\n"); public long? PetId { get; set; }
sb.Append("}\n");
return sb.ToString(); /// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
public int? Quantity { get; set; }
/// <summary>
/// Gets or Sets ShipDate
/// </summary>
[DataMember(Name="shipDate", EmitDefaultValue=false)]
public DateTime? ShipDate { get; set; }
/// <summary>
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
public bool? Complete { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
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");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
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;
}
}
} }
/// <summary>
/// Get the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
} }

View File

@ -6,89 +6,176 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model { namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Pet {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Category
/// </summary>
[DataMember(Name="category", EmitDefaultValue=false)]
public Category Category { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Gets or Sets PhotoUrls
/// </summary>
[DataMember(Name="photoUrls", EmitDefaultValue=false)]
public List<string> PhotoUrls { get; set; }
/// <summary>
/// Gets or Sets Tags
/// </summary>
[DataMember(Name="tags", EmitDefaultValue=false)]
public List<Tag> Tags { get; set; }
/// <summary>
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary> /// <summary>
/// Get the string presentation of the object ///
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class Pet : IEquatable<Pet>
var sb = new StringBuilder(); {
sb.Append("class Pet {\n");
/// <summary>
sb.Append(" Id: ").Append(Id).Append("\n"); /// Gets or Sets Id
/// </summary>
sb.Append(" Category: ").Append(Category).Append("\n"); [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n"); /// <summary>
/// Gets or Sets Category
sb.Append(" Tags: ").Append(Tags).Append("\n"); /// </summary>
[DataMember(Name="category", EmitDefaultValue=false)]
sb.Append(" Status: ").Append(Status).Append("\n"); public Category Category { get; set; }
sb.Append("}\n");
return sb.ToString(); /// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Gets or Sets PhotoUrls
/// </summary>
[DataMember(Name="photoUrls", EmitDefaultValue=false)]
public List<string> PhotoUrls { get; set; }
/// <summary>
/// Gets or Sets Tags
/// </summary>
[DataMember(Name="tags", EmitDefaultValue=false)]
public List<Tag> Tags { get; set; }
/// <summary>
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
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");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
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.Equals(other.PhotoUrls)
// ) &&
(
this.Tags == other.Tags ||
this.Tags != null &&
this.Tags.Equals(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;
}
}
} }
/// <summary>
/// Get the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
} }

View File

@ -6,52 +6,111 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model { namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Tag {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary> /// <summary>
/// Get the string presentation of the object ///
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class Tag : IEquatable<Tag>
var sb = new StringBuilder(); {
sb.Append("class Tag {\n");
/// <summary>
sb.Append(" Id: ").Append(Id).Append("\n"); /// Gets or Sets Id
/// </summary>
sb.Append(" Name: ").Append(Name).Append("\n"); [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
sb.Append("}\n");
return sb.ToString();
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
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");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
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;
}
}
} }
/// <summary>
/// Get the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
} }

View File

@ -6,107 +6,208 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model { namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class User {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Username
/// </summary>
[DataMember(Name="username", EmitDefaultValue=false)]
public string Username { get; set; }
/// <summary>
/// Gets or Sets FirstName
/// </summary>
[DataMember(Name="firstName", EmitDefaultValue=false)]
public string FirstName { get; set; }
/// <summary>
/// Gets or Sets LastName
/// </summary>
[DataMember(Name="lastName", EmitDefaultValue=false)]
public string LastName { get; set; }
/// <summary>
/// Gets or Sets Email
/// </summary>
[DataMember(Name="email", EmitDefaultValue=false)]
public string Email { get; set; }
/// <summary>
/// Gets or Sets Password
/// </summary>
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }
/// <summary>
/// Gets or Sets Phone
/// </summary>
[DataMember(Name="phone", EmitDefaultValue=false)]
public string Phone { get; set; }
/// <summary>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
public int? UserStatus { get; set; }
/// <summary> /// <summary>
/// Get the string presentation of the object ///
/// </summary> /// </summary>
/// <returns>String presentation of the object</returns> [DataContract]
public override string ToString() { public class User : IEquatable<User>
var sb = new StringBuilder(); {
sb.Append("class User {\n");
/// <summary>
sb.Append(" Id: ").Append(Id).Append("\n"); /// Gets or Sets Id
/// </summary>
sb.Append(" Username: ").Append(Username).Append("\n"); [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
sb.Append(" LastName: ").Append(LastName).Append("\n"); /// <summary>
/// Gets or Sets Username
sb.Append(" Email: ").Append(Email).Append("\n"); /// </summary>
[DataMember(Name="username", EmitDefaultValue=false)]
sb.Append(" Password: ").Append(Password).Append("\n"); public string Username { get; set; }
sb.Append(" Phone: ").Append(Phone).Append("\n");
/// <summary>
sb.Append(" UserStatus: ").Append(UserStatus).Append("\n"); /// Gets or Sets FirstName
/// </summary>
sb.Append("}\n"); [DataMember(Name="firstName", EmitDefaultValue=false)]
return sb.ToString(); public string FirstName { get; set; }
/// <summary>
/// Gets or Sets LastName
/// </summary>
[DataMember(Name="lastName", EmitDefaultValue=false)]
public string LastName { get; set; }
/// <summary>
/// Gets or Sets Email
/// </summary>
[DataMember(Name="email", EmitDefaultValue=false)]
public string Email { get; set; }
/// <summary>
/// Gets or Sets Password
/// </summary>
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }
/// <summary>
/// Gets or Sets Phone
/// </summary>
[DataMember(Name="phone", EmitDefaultValue=false)]
public string Phone { get; set; }
/// <summary>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
public int? UserStatus { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
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");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
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;
}
}
} }
/// <summary>
/// Get the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
} }

View File

@ -144,6 +144,52 @@ 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
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;
Assert.IsTrue (category1.Equals (category2));
Assert.IsTrue (tag1.Equals (tag2));
Assert.IsTrue (p1.Equals(p2));
}
} }
} }

View File

@ -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/wing328/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/wing328/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/wing328/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/wing328/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/wing328/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/wing328/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/wing328/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/bin/Debug/RestSharp.dll