C# Client Library
A C# Client Library for the AnalyzeRe REST API
ServerHasDefault.cs
Go to the documentation of this file.
1 using System;
2 
3 namespace AnalyzeRe.Attributes
4 {
7  [AttributeUsage(AttributeTargets.Property)]
8  public class ServerHasDefault : Attribute
9  {
10  private readonly object _knownDefault;
11  private readonly bool _hasKnownDefault;
12 
15  public virtual bool HasKnownDefault => HasDefaultValue(null);
16 
19  public virtual object DefaultValue
20  {
21  get
22  {
23  if (!HasKnownDefault)
24  throw new NotSupportedException(
25  "This attribute has no known default value that applies to all objects.");
26  return GetDefaultValue(null);
27  }
28  }
29 
32  public ServerHasDefault() { }
33 
38  public ServerHasDefault(object defaultValue)
39  {
40  _knownDefault = defaultValue;
41  _hasKnownDefault = true;
42  }
43 
47  protected ServerHasDefault(bool hasKnownDefault)
48  {
49  _hasKnownDefault = hasKnownDefault;
50  }
51 
56  public virtual bool HasDefaultValue(object owner)
57  {
58  return _hasKnownDefault;
59  }
60 
64  public virtual object GetDefaultValue(object owner)
65  {
66  if (!HasDefaultValue(owner))
67  throw new NotSupportedException("This attribute has no known default value.");
68  return _knownDefault;
69  }
70  }
71 }
ServerHasDefault(object defaultValue)
Attribute indicates that if left null, the server will supply the specified default value for this pr...
ServerHasDefault(bool hasKnownDefault)
Constructor that allows the derived class to specify whether it supplies a known default value for al...
virtual object GetDefaultValue(object owner)
Returns the expected default value for the property based on the owner.
Indicates that the property, if left null, will have a default value generated and filled in by the s...
virtual bool HasDefaultValue(object owner)
Returns whether there exists an expected default value for the property based on the specified owner...
ServerHasDefault()
Attribute indicates that if left null, the server will supply a default value for this property (the ...