All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp.modelGeneric.mustache Maven / Gradle / Ivy

    /// 
    /// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
    /// 
    [DataContract]
    public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>
    {
        {{#vars}}
        {{#isEnum}}
{{>modelInnerEnum}}
        {{/isEnum}}
        {{#items.isEnum}}
        {{#items}}
{{>modelInnerEnum}}
        {{/items}}
        {{/items.isEnum}}
        {{/vars}}
        {{#vars}}
        {{#isEnum}}
        /// 
        /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
        /// {{#description}}
        /// {{{description}}}{{/description}}
        [DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]
        public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; }
        {{/isEnum}}
        {{/vars}}
    {{#hasRequired}}
    {{^hasOnlyReadOnly}}
        /// 
        /// Initializes a new instance of the  class.
        /// 
        [JsonConstructorAttribute]
        protected {{classname}}() { }
    {{/hasOnlyReadOnly}}
    {{/hasRequired}}
        /// 
        /// Initializes a new instance of the  class.
        /// 
        {{#vars}}
        {{^isReadOnly}}
        /// {{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.
        {{/isReadOnly}}
        {{/vars}}
    {{#hasOnlyReadOnly}}
        [JsonConstructorAttribute]
    {{/hasOnlyReadOnly}}
        public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} = null{{^-last}}, {{/-last}}{{/readWriteVars}})
        {
            {{#vars}}
            {{^isReadOnly}}
            {{#required}}
            // to ensure "{{name}}" is required (not null)
            if ({{name}} == null)
            {
                throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null");
            }
            else
            {
                this.{{name}} = {{name}};
            }
            {{/required}}
            {{/isReadOnly}}
            {{/vars}}
            {{#vars}}
            {{^isReadOnly}}
            {{^required}}
            {{#defaultValue}}// use default value if no "{{name}}" provided
            if ({{name}} == null)
            {
                this.{{name}} = {{{defaultValue}}};
            }
            else
            {
                this.{{name}} = {{name}};
            }
            {{/defaultValue}}
            {{^defaultValue}}
this.{{name}} = {{name}};
            {{/defaultValue}}
            {{/required}}
            {{/isReadOnly}}
            {{/vars}}
        }
        
        {{#vars}}
        {{^isEnum}}
        /// 
        /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
        /// {{#description}}
        /// {{description}}{{/description}}
        [DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]
        public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
        {{/isEnum}}
        {{/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)
        {
            // credit: http://stackoverflow.com/a/10454552/677735
            return this.Equals(obj as {{classname}});
        }

        /// 
        /// Returns true if {{classname}} instances are equal
        /// 
        /// Instance of {{classname}} to be compared
        /// Boolean
        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}}{{^vars}}false{{/vars}};
        }

        /// 
        /// Gets the hash code
        /// 
        /// Hash code
        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 * 59 + this.{{name}}.GetHashCode();
                {{/vars}}
                return hash;
            }
        }
    }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy