C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Reference.cs
Go to the documentation of this file.
1using System.Runtime.Serialization;
3
4// ReSharper disable once CheckNamespace (Want to hide the non-generic reference
5// to discourage use, but keep this next to related reference classes.)
6// ReSharper disable NonReadonlyMemberInGetHashCode
7// We only compute the hashCode the first time it's needed, then never modify it.
8// Furthermore, the ref_id of a reference should never be changed after construction,
9// it's only modifiable for deserialization purposes.
10namespace AnalyzeRe.APITypes
11{
14 public abstract class Reference : APIType, IReference
15 {
17 private int? _hashCode;
18
19 #region Public Properties
27 [DataMember(Order = 1)]
28 public string reference_type { get; protected set; }
29
31 [DataMember(Order = 2)]
32 public string ref_id { get; protected set; }
33
35 [DataMember(Order = 3)]
37 public string href { get; protected set; }
38 #endregion Public Properties
39
40 #region Constructors
46 protected Reference(string ref_id, string href)
47 {
48 this.ref_id = ref_id;
49 this.href = href;
50 }
51 #endregion Constructors
52
53 #region Equality and Object overrides
57 public override bool Equals(object obj)
58 {
60 ref_id != null &&
61 Equals(ref_id, objReference.ref_id);
62 }
63
66 public override int GetHashCode()
67 {
68 if (!_hashCode.HasValue)
69 _hashCode = ref_id?.GetHashCode() ?? base.GetHashCode();
70 return _hashCode.Value;
71 }
72
75 public override string ToString()
76 {
77 return ref_id ?? "(empty)";
78 }
79 #endregion Equality and Object overrides
80 }
81}
Base class used by all types and resources.
Definition APIType.cs:8
Implements the basic reference entity interface, but has no support for resolving references.
Definition Reference.cs:15
override int GetHashCode()
Serves as a hash function for reference objects.
Definition Reference.cs:66
override bool Equals(object obj)
Determines whether the two reference objects refer to the same object.
Definition Reference.cs:57
Reference(string ref_id, string href)
Creates a new reference class that refers to an object with the specified id, type,...
Definition Reference.cs:46
string href
The HREF that can be used to retrieve the object being referred to.
Definition Reference.cs:37
string reference_type
In cases where a model can reference resources belonging to one of a number of collections,...
Definition Reference.cs:28
override string ToString()
Returns this reference's id.
Definition Reference.cs:75
string ref_id
The id of the object being referred to.
Definition Reference.cs:32
Describes a collection of resources which can be listed.
Specifies that a property is generated by the server and should not be specified on the client side d...
Base interface for all reference entities.