nancyfx.modelGeneric.mustache Maven / Gradle / Ivy
///
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
///
public {{^hasChildren}}sealed {{/hasChildren}}class {{classname}}: {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>
{ {{#vars}}{{^isInherited}}
///
/// {{^description}}{{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
///
public {{>nullableDataType}} {{name}} { get; private set; }
{{/isInherited}}{{/vars}}
///
/// Empty constructor required by some serializers.
/// Use {{classname}}.Builder() for instance creation instead.
///
[Obsolete]
public {{classname}}(){{#parent}} : base({{/parent}}{{#parentVars}}null{{#hasMore}}, {{/hasMore}}{{/parentVars}}{{#parent}}){{/parent}}
{
}
{{#hasChildren}}protected{{/hasChildren}}{{^hasChildren}}private{{/hasChildren}} {{classname}}({{#vars}}{{>nullableDataType}} {{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}){{#parent}} : base({{#parentVars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/parentVars}}){{/parent}}
{
{{#vars}}{{^isInherited}}
this.{{name}} = {{name}};
{{/isInherited}}{{/vars}}
}
///
/// Returns builder of {{classname}}.
///
/// {{classname}}Builder
public static {{#parent}}new {{/parent}}{{classname}}Builder Builder()
{
return new {{classname}}Builder();
}
///
/// Returns {{classname}}Builder with properties set.
/// Use it to change properties.
///
/// {{classname}}Builder
public {{#parent}}new {{/parent}}{{classname}}Builder With()
{
return Builder()
{{#vars}}
.{{name}}({{name}}){{#hasMore}}
{{/hasMore}}{{/vars}};
}
public override string ToString()
{
return this.PropertiesToString();
}
public override bool Equals(object obj)
{
return this.EqualsByProperties(obj);
}
public bool Equals({{classname}} other)
{
return Equals((object) other);
}
public override int GetHashCode()
{
return this.PropertiesHash();
}
///
/// Implementation of == operator for ({{classname}}.
///
/// Compared ({{classname}}
/// Compared ({{classname}}
/// true if compared items are equals, false otherwise
public static bool operator == ({{classname}} left, {{classname}} right)
{
return Equals(left, right);
}
///
/// Implementation of != operator for ({{classname}}.
///
/// Compared ({{classname}}
/// Compared ({{classname}}
/// true if compared items are not equals, false otherwise
public static bool operator != ({{classname}} left, {{classname}} right)
{
return !Equals(left, right);
}
///
/// Builder of {{classname}}.
///
public sealed class {{classname}}Builder
{
{{#vars}}
private {{>nullableDataType}} _{{name}};
{{/vars}}
internal {{classname}}Builder()
{
SetupDefaults();
}
private void SetupDefaults()
{
{{#vars}}
{{^required}}
{{#defaultValue}}
_{{name}} = {{{defaultValue}}};
{{/defaultValue}}
{{/required}}
{{/vars}}
}
{{#vars}}
///
/// Sets value for {{classname}}.{{{name}}} property.
///
/// {{^description}}{{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
public {{classname}}Builder {{name}}({{>nullableDataType}} value)
{
_{{name}} = value;
return this;
}
{{/vars}}
///
/// Builds instance of {{classname}}.
///
/// {{classname}}
public {{classname}} Build()
{
Validate();
return new {{classname}}(
{{#vars}}
{{name}}: _{{name}}{{#hasMore}},{{/hasMore}}
{{/vars}}
);
}
private void Validate()
{ {{#vars}}{{#required}}
if (_{{name}} == null)
{
throw new ArgumentException("{{name}} is a required property for {{classname}} and cannot be null");
} {{/required}}{{/vars}}
}
}
{{#vars}}{{#isEnum}}{{^parent}}
{{>innerModelEnum}}{{/parent}}{{/isEnum}}{{#items.isEnum}}
{{#items}}{{>innerModelEnum}}{{/items}}{{/items.isEnum}}{{/vars}}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy