-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAggregateFunction.cs
More file actions
70 lines (56 loc) · 1.93 KB
/
AggregateFunction.cs
File metadata and controls
70 lines (56 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#if !SYSTEM_TEXT_JSON
using Newtonsoft.Json;
#endif
using Queries.Core.Attributes;
using Queries.Core.Parts.Columns;
using System;
namespace Queries.Core.Parts.Functions;
/// <summary>
/// Base class for all aggregate functions.
/// </summary>
[Function]
#if !SYSTEM_TEXT_JSON
[JsonObject]
#endif
public abstract class AggregateFunction : IAliasable<AggregateFunction>, IEquatable<AggregateFunction>, IColumn
{
/// <summary>
/// The type of aggregate the current instance represents
/// </summary>
public AggregateType Type { get; }
/// <summary>
/// The column onto which the current function will be applied
/// </summary>
public IColumn Column { get; }
/// <summary>
/// Builds a new <see cref="AggregateFunction"/> instance.
/// </summary>
/// <param name="aggregate">The aggregate function to create</param>
/// <param name="column">The column onto which the aggregate will be applied</param>
/// <exception cref="ArgumentNullException">if <paramref name="column"/> is null.</exception>
protected AggregateFunction(AggregateType aggregate, IColumn column)
{
Type = aggregate;
Column = column ?? throw new ArgumentNullException(nameof(column));
}
/// <summary>
/// The alias associated with the column
/// </summary>
public string Alias { get; private set; }
///<inheritdoc/>
public virtual AggregateFunction As(string alias)
{
Alias = alias;
return this;
}
///<inheritdoc/>
public override bool Equals(object obj) => Equals(obj as AggregateFunction);
///<inheritdoc/>
public bool Equals(AggregateFunction other) => (Column, Alias).Equals((other?.Column, other?.Alias));
///<inheritdoc/>
public override int GetHashCode() => (Column, Alias).GetHashCode();
///<inheritdoc/>
public override string ToString() => this.Jsonify();
///<inheritdoc/>
public abstract IColumn Clone();
}