handlebars.aspnetcore.model.mustache Maven / Gradle / Ivy
{{>partial_header}}
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
{{#models}}
{{#model}}
namespace {{packageName}}.Models
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
///
/// {{description}}
///
[DataContract]
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>
{ {{#vars}}{{#isEnum}}{{^isContainer}}{{>enumClass}}{{/isContainer}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{^isContainer}}{{>enumClass}}{{/isContainer}}{{/items}}{{/items.isEnum}}
///
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
///
{{#description}}
/// {{description}}
{{/description}}
{{#required}}
[Required]
{{/required}}{{#pattern}}
[RegularExpression("{{{pattern}}}")]{{/pattern}}{{#minLength}}{{#maxLength}}
[StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
[MaxLength({{maxLength}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
[DataMember(Name="{{baseName}}")]
{{#isEnum}}
public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; }
{{/isEnum}}
{{^isEnum}}
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
{{/isEnum}}
{{#hasMore}}
{{/hasMore}}
{{/vars}}
///
/// Returns the string presentation of the object
///
/// String presentation of the object
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();
}
///
/// Returns the JSON string presentation of the object
///
/// JSON string presentation of the object
public {{#parent}} new {{/parent}}string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
///
/// Returns true if objects are equal
///
/// Object to be compared
/// Boolean
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals(({{classname}})obj);
}
///
/// Returns true if {{classname}} instances are equal
///
/// Instance of {{classname}} to be compared
/// Boolean
public bool Equals({{classname}} other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return {{#vars}}{{#isNotContainer}}
(
{{name}} == other.{{name}} ||
{{name}} != null &&
{{name}}.Equals(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}}
(
{{name}} == other.{{name}} ||
{{name}} != null &&
{{name}}.SequenceEqual(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}}{{^vars}}false{{/vars}};
}
///
/// Gets the hash code
///
/// Hash code
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
var hashCode = 41;
// Suitable nullity checks etc, of course :)
{{#vars}}
if ({{name}} != null)
hashCode = hashCode * 59 + {{name}}.GetHashCode();
{{/vars}}
return hashCode;
}
}
#region Operators
#pragma warning disable 1591
public static bool operator ==({{classname}} left, {{classname}} right)
{
return Equals(left, right);
}
public static bool operator !=({{classname}} left, {{classname}} right)
{
return !Equals(left, right);
}
#pragma warning restore 1591
#endregion Operators
}
{{/isEnum}}
{{/model}}
{{/models}}
}